fix(drizzle): in query on polymorphic relations across ID types (#8240)

Fixes querying using `in` operator by polymorphic relationship value.
The previous PR https://github.com/payloadcms/payload/pull/8191 didn't
handle the case when the incoming query value is an array and therefore
each item of the array can have a different type.
Ensures test coverage
This commit is contained in:
Sasha
2024-09-17 19:57:00 +03:00
committed by GitHub
parent 9035467998
commit 31ffc57366
3 changed files with 93 additions and 10 deletions

View File

@@ -587,6 +587,46 @@ describe('Relationships', () => {
expect(customIDNumberResult.totalDocs).toBe(1)
expect(customIDNumberResult.docs[0].id).toBe(relToCustomIdNumber.id)
const inResult_1 = await payload.find({
collection: 'rels-to-pages-and-custom-text-ids',
where: {
'rel.value': {
in: [page.id, customIDNumber.id],
},
},
})
expect(inResult_1.totalDocs).toBe(2)
expect(inResult_1.docs.some((each) => each.id === relToPage.id)).toBeTruthy()
expect(inResult_1.docs.some((each) => each.id === relToCustomIdNumber.id)).toBeTruthy()
const inResult_2 = await payload.find({
collection: 'rels-to-pages-and-custom-text-ids',
where: {
'rel.value': {
in: [customIDNumber.id, customIDText.id],
},
},
})
expect(inResult_2.totalDocs).toBe(2)
expect(inResult_2.docs.some((each) => each.id === relToCustomIdText.id)).toBeTruthy()
expect(inResult_2.docs.some((each) => each.id === relToCustomIdNumber.id)).toBeTruthy()
const inResult_3 = await payload.find({
collection: 'rels-to-pages-and-custom-text-ids',
where: {
'rel.value': {
in: [customIDNumber.id, customIDText.id, page.id],
},
},
})
expect(inResult_3.totalDocs).toBe(3)
expect(inResult_3.docs.some((each) => each.id === relToCustomIdText.id)).toBeTruthy()
expect(inResult_3.docs.some((each) => each.id === relToCustomIdNumber.id)).toBeTruthy()
expect(inResult_3.docs.some((each) => each.id === relToPage.id)).toBeTruthy()
})
})