payloadcms / payloadcms/payload
Allow joins: false for collections without generated join fields
Nobody has claimed this yet.
- 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
falseor 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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