#13843·payload

Referenced documents can still be unpublished

Author: lcnogueiraCreated Sep 17, 2025Updated Sep 16, 2026
Labelsarea: coreBug

Describe the Bug

If one document is being referenced in a relationship field, we can prevent unpublished documents from being added to that field, by using a filter:

return {
          _status: {
            equals: 'published',
          },
        };

However, AFTER selecting the published document in the relationship field, that same document can still be unpublished. This causes a lot of issues, since published pages will remain pointing to unpublished documents. I see a few possible solutions, but I'm not sure which one would be the most viable:

  • Exposing a flag (i.e. weak: true or weak:false) that we could set when creating a relationship field that would throw an error by default if we tried to unpublish a document that is being referenced somewhere. IMHO, this is the ideal solution.
  • Using a hook to compare the previous _status with the new _status. However, this won't work if we have drafts and autosave enabled, since we are not able to determine if it's changing from published to _status because the user is unpublishing the document or just because they updated any content (since drafts and autosave are enabled).
  • Exposing an unpublish option under admin.components.edit that would allow us to implement this check before effectively unpublishing the document.
Image

Link to the code that reproduces this issue

https://github.com/lcnogueira/payload-draft-published-issue

Reproduction Steps

  • Install the packages: pnpm install.
  • Ensure you have the proper env variables under your .env file:
DATABASE_URI=mongodb://127.0.0.1/drafts-published-bug
PAYLOAD_SECRET=any-string-you-want
  • Use docker to start the database: docker-compose up.
  • Start the project: pnpm run dev.
  • Create an entry in the Places collection and publish it.
  • Create an entry in the Posts collection and select the place you just published in the Reference to Place Collection field:
Image
  • Open the published Places entry again and ensure you can unpublish it, even though it's being referenced by the Post entry.

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

`
Binaries:
  Node: 23.11.1
  npm: 10.9.2
  Yarn: 1.22.19
  pnpm: 10.14.0
Relevant Packages:
  payload: 3.56.0
  next: 15.4.4
  @payloadcms/db-mongodb: 3.56.0
  @payloadcms/email-nodemailer: 3.56.0
  @payloadcms/graphql: 3.56.0
  @payloadcms/next/utilities: 3.56.0
  @payloadcms/payload-cloud: 3.56.0
  @payloadcms/richtext-lexical: 3.56.0
  @payloadcms/translations: 3.56.0
  @payloadcms/ui/shared: 3.56.0
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:39 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6020
  Available memory (MB): 16384
  Available CPU cores: 10