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:
@@ -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: {} })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user