diff --git a/packages/drizzle/src/queries/getTableColumnFromPath.ts b/packages/drizzle/src/queries/getTableColumnFromPath.ts index 6be74fe3504..63a86b8f7b8 100644 --- a/packages/drizzle/src/queries/getTableColumnFromPath.ts +++ b/packages/drizzle/src/queries/getTableColumnFromPath.ts @@ -727,6 +727,7 @@ export const getTableColumnFromPath = ({ if ( Array.isArray(value) && + value.length > 0 && value.every((val) => typeof val === 'number') && idTypeTextOrUuid ) { @@ -749,6 +750,7 @@ export const getTableColumnFromPath = ({ if ( Array.isArray(value) && + value.length > 0 && idType === 'uuid' && hasCustomCollectionWithCustomID && !value.some((val) => uuidValidate(val)) diff --git a/test/relationships/int.spec.ts b/test/relationships/int.spec.ts index a446538e14f..ebbe6e99e44 100644 --- a/test/relationships/int.spec.ts +++ b/test/relationships/int.spec.ts @@ -1709,6 +1709,40 @@ describe('Relationships', () => { }) describe('Polymorphic Relationships', () => { + it('should return no documents for an empty in query on a polymorphic relationship', async () => { + const movie = await payload.create({ + collection: 'movies', + data: { + name: 'Empty in query movie', + }, + }) + const relationship = await payload.create({ + collection: polymorphicRelationshipsSlug, + data: { + polymorphic: { + relationTo: 'movies', + value: movie.id, + }, + }, + }) + + try { + const result = await payload.find({ + collection: polymorphicRelationshipsSlug, + where: { + 'polymorphic.value': { + in: [], + }, + }, + }) + + expect(result.docs).toHaveLength(0) + } finally { + await payload.delete({ id: relationship.id, collection: polymorphicRelationshipsSlug }) + await payload.delete({ id: movie.id, collection: 'movies' }) + } + }) + it('should allow REST querying on polymorphic relationships', async () => { const movie = await payload.create({ collection: 'movies',