fix: respect draft: true when querying docs for the join field (#11763)

Previously, if you were querying a collection that has a join field with
`draft: true`, and the join field's collection also has
`versions.drafts: true` our db adapter would still query the original
SQL table / mongodb collection instead of the versions one which isn't
quite right since we respect `draft: true` when populating relationships
This commit is contained in:
Sasha
2025-03-24 15:49:30 +02:00
committed by GitHub
parent 5f6bb92501
commit 1b2b6a1b15
17 changed files with 165 additions and 29 deletions

View File

@@ -606,6 +606,27 @@ describe('Joins Field', () => {
expect(res.docs[0].relatedVersions.docs[0].id).toBe(version.id)
})
it('should populate joins with hasMany when on both sides documents are in draft', async () => {
const category = await payload.create({
collection: 'categories-versions',
data: { _status: 'draft' },
draft: true,
})
const version = await payload.create({
collection: 'versions',
data: { _status: 'draft', categoryVersion: category.id },
draft: true,
})
const res = await payload.find({
collection: 'categories-versions',
draft: true,
})
expect(res.docs[0].relatedVersions.docs[0].id).toBe(version.id)
})
it('should populate joins when versions on both sides draft true payload.db.queryDrafts', async () => {
const category = await payload.create({ collection: 'categories-versions', data: {} })