fix(db-postgres): querying multiple hasMany text or number fields (#14028)
Fixes https://github.com/payloadcms/payload/issues/14023
This commit is contained in:
@@ -127,6 +127,11 @@ const TextFields: CollectionConfig = {
|
||||
type: 'text',
|
||||
hasMany: true,
|
||||
},
|
||||
{
|
||||
name: 'hasManySecond',
|
||||
type: 'text',
|
||||
hasMany: true,
|
||||
},
|
||||
{
|
||||
name: 'readOnlyHasMany',
|
||||
type: 'text',
|
||||
|
||||
@@ -165,6 +165,43 @@ describe('Fields', () => {
|
||||
expect(missResult).toBeFalsy()
|
||||
})
|
||||
|
||||
it('should query multiple hasMany fields', async () => {
|
||||
await payload.delete({ collection: 'text-fields', where: {} })
|
||||
const hit = await payload.create({
|
||||
collection: 'text-fields',
|
||||
data: {
|
||||
hasMany: ['1', '2', '3'],
|
||||
hasManySecond: ['4'],
|
||||
text: 'required',
|
||||
},
|
||||
})
|
||||
|
||||
const miss = await payload.create({
|
||||
collection: 'text-fields',
|
||||
data: {
|
||||
hasMany: ['6'],
|
||||
hasManySecond: ['4'],
|
||||
text: 'required',
|
||||
},
|
||||
})
|
||||
|
||||
const { docs } = await payload.find({
|
||||
collection: 'text-fields',
|
||||
where: {
|
||||
hasMany: { equals: '3' },
|
||||
hasManySecond: {
|
||||
equals: '4',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const hitResult = docs.find(({ id: findID }) => hit.id === findID)
|
||||
const missResult = docs.find(({ id: findID }) => miss.id === findID)
|
||||
|
||||
expect(hitResult).toBeDefined()
|
||||
expect(missResult).toBeFalsy()
|
||||
})
|
||||
|
||||
it('should query like on value', async () => {
|
||||
const miss = await payload.create({
|
||||
collection: 'text-fields',
|
||||
|
||||
@@ -769,6 +769,7 @@ export interface TextField {
|
||||
fieldWithDefaultValue?: string | null;
|
||||
dependentOnFieldWithDefaultValue?: string | null;
|
||||
hasMany?: string[] | null;
|
||||
hasManySecond?: string[] | null;
|
||||
readOnlyHasMany?: string[] | null;
|
||||
validatesHasMany?: string[] | null;
|
||||
localizedHasMany?: string[] | null;
|
||||
@@ -3256,6 +3257,7 @@ export interface TextFieldsSelect<T extends boolean = true> {
|
||||
fieldWithDefaultValue?: T;
|
||||
dependentOnFieldWithDefaultValue?: T;
|
||||
hasMany?: T;
|
||||
hasManySecond?: T;
|
||||
readOnlyHasMany?: T;
|
||||
validatesHasMany?: T;
|
||||
localizedHasMany?: T;
|
||||
|
||||
Reference in New Issue
Block a user