payloadcms / public-demo

The official public demo for Payload
https://demo.payloadcms.com
152 stars 74 forks source link

fix: link field relationship should be empty if custom type #25

Closed creative-andrew closed 1 year ago

creative-andrew commented 1 year ago

How to reproduce:

  1. Go to the demo site and create a new post.

  2. Add in the Page layout a content block.

  3. Add a link to the content block first using Internal link as type .

  4. Save and the response should be like this including the corresponding reference object.

    "links": [
    {
      "link": {
        "type": "reference",
        "label": "fdfdfd",
        "reference": {
          "value": {
            "id": "64cb7aa12ad37e39db23ecef",
            "hero": {
              "type": "contentMedia",
              "basic": {
    
              },
              "content": {
    
              },
              "contentMedia": {
                "links": [
                  {
                    "link": {
                      "appearance": "text",
                      "type": "custom",
                      "label": "Documentation",
                      "reference": null,
                      "url": "https://payloadcms.com/docs/getting-started/what-is-payload"
                    },
                    "id": "61f9b0479d0e9c0b6424c3e0"
                  }
                ],
                "media": "64cb7aa12ad37e39db23ecd9",
                "embeddedVideo": {
                  "embed": true,
                  "poster": "64cb7aa12ad37e39db23ecd9",
                  "platform": "youtube",
                  "videoID": "bxWsZTtqs80",
                  "aspectRatio": "56.25"
                }
              },
              "contentSidebar": {
    
              },
              "fullscreenBackground": {
    
              },
              "quickNav": {
    
              },
              "fullscreenSlider": {
    
              }
            },
            "author": "64cb7aa12ad37e39db23ecd6",
            "parent": "64cb7aa12ad37e39db23ecdb",
            "meta": {
    
            },
            "_status": "published",
            "createdAt": "2023-08-03T10:00:02.007Z",
            "updatedAt": "2023-08-03T10:00:03.573Z"
          },
          "relationTo": "pages"
        }
      },
      "id": "64cb85283ae7938606124ba8"
    }
    ],
  5. Modify the link to custom type and save. You will notice that the reference is still saved in the field even tho we are using a custom-type link

"links": [
  {
    "link": {
      "type": "custom",
      "label": "fdfdfd",
      "reference": {
        "value": {
          "id": "64cb7aa12ad37e39db23ecef",
          "hero": {
            "type": "contentMedia",
            "basic": {

            },
            "content": {

            },
            "contentMedia": {
              "links": [
                {
                  "link": {
                    "appearance": "text",
                    "type": "custom",
                    "label": "Documentation",
                    "reference": null,
                    "url": "https://payloadcms.com/docs/getting-started/what-is-payload"
                  },
                  "id": "61f9b0479d0e9c0b6424c3e0"
                }
              ],
              "media": "64cb7aa12ad37e39db23ecd9",
              "embeddedVideo": {
                "embed": true,
                "poster": "64cb7aa12ad37e39db23ecd9",
                "platform": "youtube",
                "videoID": "bxWsZTtqs80",
                "aspectRatio": "56.25"
              }
            },
            "contentSidebar": {

            },
            "fullscreenBackground": {

            },
            "quickNav": {

            },
            "fullscreenSlider": {

            }
          },
          "author": "64cb7aa12ad37e39db23ecd6",
          "parent": "64cb7aa12ad37e39db23ecdb",
          "meta": {

          },
          "_status": "published",
          "createdAt": "2023-08-03T10:00:02.007Z",
          "updatedAt": "2023-08-03T10:00:03.573Z"
        },
        "relationTo": "pages"
      },
      "url": "dfddf"
    },
    "id": "64cb85283ae7938606124ba8"
  }
],

Props: @italodr

JarrodMFlesch commented 1 year ago

I think this is a good change, cuts down on the response object/size too.