payloadcms / payloadcms/payload

Allow joins: false for collections without generated join fields

Open Beginner friendly
#17,904 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

v4
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

Describe the bug

Local API query options document joins: false as the way to disable all join fields. Runtime handling also accepts false.

However, JoinQuery<TSlug> resolves to never when the collection has no entry in generated collectionsJoins. Consequently:

await payload.find({
  collection: 'pages',
  joins: false,
})

produces:

Type 'false' is not assignable to type 'undefined'.

Payload's current type suite explicitly expects JoinQuery<'pages'> to be never when pages has no joins, so this appears intentional rather than an accidental regression.

Generic wrappers cannot always know whether the supplied collection has join fields. They should be able to pass false consistently to guarantee that no join population occurs without casts or @ts-expect-error.

Expected behavior
  • Collections with joins accept false or the generated join query.
  • Collections without joins accept false, but reject object join queries.

This could be implemented by moving false outside the conditional in JoinQuery, with type tests covering both collection shapes.

Payload version

Reproduced with Payload 3.87.0 and current main (db7543c2121f0b672e33436447122b5e09ea4f2b).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the JoinQuery definition and the existing type tests covering collections with and without entries in generated collectionsJoins. Run those type tests first, then update coverage so false is accepted for both collection shapes while object join queries remain rejected for collections without joins.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.