Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[MongoDB] Join fields are disregarded when querying a versioned collection with draft true #11355

Open
dpnolte opened this issue Feb 23, 2025 · 0 comments
Labels
status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@dpnolte
Copy link

dpnolte commented Feb 23, 2025

Describe the Bug

When having a collection with versions and draft enabled, the join fields are lost when setting draft to false.
I would expect also to get the join fields values since that is also shown that way in the admin panel.

For a draft category document that has a join field to posts, it is shown as follows in the admin panel with status indicating 'draft':

Image

Join field exists in api response with checkbox draft unchecked:

Image

Join field missing in api response with checkbox draft checked:

Image

The join fields are also missing when querying with the local api:

const category = await req.payload.findByID({ collections: 'categories', id: 'bla', draft: true });
// category misses posts join field

The join fields values seem to be removed in the replaceWithDraftIfAvailable function: https://github.com/payloadcms/payload/blob/4224c680023707fff7d67cacd9dbd75b77f4128c/packages/payload/src/versions/drafts/replaceWithDraftIfAvailable.ts

Link to the code that reproduces this issue

https://github.com/dpnolte/payload-missing-join-fields-draft

Reproduction Steps

  • Clone, start docker container & dev mode from the repo
  • In admin panel, add a category and a post
  • Go to category edit view. Notice that the join field is shown
  • Go to API tab.
  • The post join field are shown when 'draft' checkbox is unchecked.
  • Uncheck 'draft' checkbox
  • The posts join field is missing

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

db-mongodb

Environment Info

Binaries:
  Node: 22.14.0
  npm: 10.9.2
  Yarn: 1.22.19
  pnpm: 9.15.4
Relevant Packages:
  payload: 3.24.0
  next: 15.1.5
  @payloadcms/db-mongodb: 3.24.0
  @payloadcms/email-nodemailer: 3.24.0
  @payloadcms/graphql: 3.24.0
  @payloadcms/next/utilities: 3.24.0
  @payloadcms/payload-cloud: 3.24.0
  @payloadcms/richtext-lexical: 3.24.0
  @payloadcms/translations: 3.24.0
  @payloadcms/ui/shared: 3.24.0
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
@dpnolte dpnolte added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Feb 23, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

1 participant