feat(drizzle): add support for in and not_in operators on json field (#8148)
Closes https://github.com/payloadcms/payload/issues/7952 Adds support for `in` and `not_in` operator against JSON field filters. The following queries are now valid in postgres as well, previously it only worked in mongo ```ts await payload.find({ collection: 'posts', where: { 'data.value': { in: ['12', '13', '14'], }, }, context: { disable: true, }, }) await payload.find({ collection: 'posts', where: { 'data.value': { not_in: ['12', '13', '14'], }, }, context: { disable: true, }, }) ```
This commit is contained in:
@@ -1744,6 +1744,16 @@ describe('Fields', () => {
|
||||
json: { baz: 'bar', number: 10 },
|
||||
},
|
||||
})
|
||||
|
||||
// Create content for array 'in' and 'not_in' queries
|
||||
for (let i = 1; i < 6; i++) {
|
||||
await payload.create({
|
||||
collection: 'json-fields',
|
||||
data: {
|
||||
json: { value: i },
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('should query nested properties - like', async () => {
|
||||
@@ -1901,6 +1911,36 @@ describe('Fields', () => {
|
||||
|
||||
expect(result.docs).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('should query nested numbers - in', async () => {
|
||||
const { docs } = await payload.find({
|
||||
collection: 'json-fields',
|
||||
where: {
|
||||
'json.value': { in: [1, 3] },
|
||||
},
|
||||
})
|
||||
|
||||
const docIDs = docs.map(({ json }) => json.value)
|
||||
|
||||
expect(docIDs).toContain(1)
|
||||
expect(docIDs).toContain(3)
|
||||
expect(docIDs).not.toContain(2)
|
||||
})
|
||||
|
||||
it('should query nested numbers - not_in', async () => {
|
||||
const { docs } = await payload.find({
|
||||
collection: 'json-fields',
|
||||
where: {
|
||||
'json.value': { not_in: [1, 3] },
|
||||
},
|
||||
})
|
||||
|
||||
const docIDs = docs.map(({ json }) => json.value)
|
||||
|
||||
expect(docIDs).not.toContain(1)
|
||||
expect(docIDs).not.toContain(3)
|
||||
expect(docIDs).toContain(2)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user