Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Self-Join Depths Greater Than 1 Not Working #10243

Closed
tobiasiv opened this issue Dec 30, 2024 · 3 comments
Closed

Self-Join Depths Greater Than 1 Not Working #10243

tobiasiv opened this issue Dec 30, 2024 · 3 comments
Assignees

Comments

@tobiasiv
Copy link

Describe the Bug

The depth parameter for self-joins does not work as expected. It only applies correctly for depths 0 and 1. For example, if you have nested categories up to depth 5, the depth parameter will not fetch beyond the first level of children.

Link to the code that reproduces this issue

https://github.com/tobiasiv/payload-reproduction/tree/self-join-depth

Reproduction Steps

  1. Clone the reproduction repo (branch: self-join-depth)
  2. Set the env variables
  3. pnpm dev
  4. Go to collection Categories and open the document Parent
  5. Switch to the API Tab
  6. Set the depth to 0: You will only see the IDs of the child docs
  7. Set the depth to 1: Children at depth 1 will be fully fetched, and you will see only the IDs of the grandchildren docs
  8. Set the depth to a number greater than 1: The behavior remains the same as with depth 1

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

area: core

Environment Info

Binaries:
  Node: 20.16.0
  npm: N/A
  Yarn: N/A
  pnpm: 9.7.0
Relevant Packages:
  payload: 3.12.0
  next: 15.1.0
  @payloadcms/db-mongodb: 3.12.0
  @payloadcms/db-postgres: 3.12.0
  @payloadcms/email-nodemailer: 3.12.0
  @payloadcms/graphql: 3.12.0
  @payloadcms/next/utilities: 3.12.0
  @payloadcms/payload-cloud: 3.12.0
  @payloadcms/richtext-lexical: 3.12.0
  @payloadcms/ui/shared: 3.12.0
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
  Available memory (MB): 16263
  Available CPU cores: 8
@tobiasiv tobiasiv added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Dec 30, 2024
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Dec 30, 2024
@r1tsuu r1tsuu self-assigned this Jan 3, 2025
@r1tsuu
Copy link
Member

r1tsuu commented Jan 3, 2025

I added some tests here #10336 to confirm that it's not an issue but happens because the default maxDepth for join fields is 1.

You need to increase it if you want your join field to be populated within other relationship / join fields. https://payloadcms.com/docs/fields/join#config-options

@r1tsuu r1tsuu closed this as completed Jan 3, 2025
DanRibbens pushed a commit that referenced this issue Jan 3, 2025
…SDoc (#10336)

Allows to set `maxDepth: 0` for join fields and improves JSDoc about
`maxDepth`, adds tests to confirm that
#10243 is not an issue, but
just happens because the default `maxDepth` is `1`.
@tobiasiv
Copy link
Author

tobiasiv commented Jan 3, 2025

I added some tests here #10336 to confirm that it's not an issue but happens because the default maxDepth for join fields is 1.

You need to increase it if you want your join field to be populated within other relationship / join fields. https://payloadcms.com/docs/fields/join#config-options

Thanks! I wasn't aware of the maxDepth config.

Copy link
Contributor

github-actions bot commented Jan 5, 2025

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants