fix(db-postgres): querying multiple hasMany text or number fields (#14028)

Fixes https://github.com/payloadcms/payload/issues/14023
This commit is contained in:
Sasha
2025-10-02 05:30:04 +03:00
committed by GitHub
parent 1e654c0a95
commit 95bdffd11f
4 changed files with 62 additions and 8 deletions

View File

@@ -127,6 +127,11 @@ const TextFields: CollectionConfig = {
type: 'text',
hasMany: true,
},
{
name: 'hasManySecond',
type: 'text',
hasMany: true,
},
{
name: 'readOnlyHasMany',
type: 'text',

View File

@@ -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',

View File

@@ -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;