Skip to content

Commit 0407620

Browse files
committed
test(drizzle): sort by join field on versioned collection with custom text id
Adds a regression test that creates a versioned collection with a custom text id and `join` fields (covering both the hasMany and non-hasMany branches in `getTableColumnFromPath`), then runs `payload.find` with `draft: true` and `sort` set to the join field. Without the fix this fails with: operator does not exist: character varying = integer Made-with: Cursor
1 parent 6b9847f commit 0407620

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

‎test/joins/config.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
postsSlug,
2222
restrictedCategoriesSlug,
2323
restrictedPostsSlug,
24+
textIdCategoriesVersionsSlug,
25+
textIdPostsSlug,
2426
} from './shared.js'
2527

2628
const filename = fileURLToPath(import.meta.url)
@@ -340,6 +342,44 @@ export default buildConfigWithDefaults({
340342
},
341343
FolderPoly1,
342344
FolderPoly2,
345+
{
346+
slug: textIdCategoriesVersionsSlug,
347+
versions: { drafts: true },
348+
fields: [
349+
{ name: 'id', type: 'text' },
350+
{ name: 'name', type: 'text' },
351+
{
352+
name: 'relatedSingle',
353+
type: 'join',
354+
collection: textIdPostsSlug,
355+
on: 'category',
356+
},
357+
{
358+
name: 'relatedMany',
359+
type: 'join',
360+
collection: textIdPostsSlug,
361+
on: 'categories',
362+
},
363+
],
364+
},
365+
{
366+
slug: textIdPostsSlug,
367+
fields: [
368+
{ name: 'id', type: 'text' },
369+
{ name: 'title', type: 'text' },
370+
{
371+
name: 'category',
372+
type: 'relationship',
373+
relationTo: textIdCategoriesVersionsSlug,
374+
},
375+
{
376+
name: 'categories',
377+
type: 'relationship',
378+
relationTo: textIdCategoriesVersionsSlug,
379+
hasMany: true,
380+
},
381+
],
382+
},
343383
],
344384
localization: {
345385
locales: [

‎test/joins/int.spec.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,40 @@ describe('Joins Field', () => {
866866

867867
expect(res.docs[0].relatedVersionsMany.docs[0].id).toBe(version.id)
868868
})
869+
870+
it('should not crash when sorting drafts by a join field on a versioned collection with custom text id', async () => {
871+
const category = await payload.create({
872+
collection: 'text-id-categories-versions' as never,
873+
data: { id: 'cat-text-1', name: 'cat-1' } as never,
874+
})
875+
876+
await payload.create({
877+
collection: 'text-id-posts' as never,
878+
data: {
879+
id: 'post-text-1',
880+
title: 'post-1',
881+
category: (category as { id: string }).id,
882+
categories: [(category as { id: string }).id],
883+
} as never,
884+
})
885+
886+
const single = await payload.find({
887+
collection: 'text-id-categories-versions' as never,
888+
draft: true,
889+
sort: 'relatedSingle',
890+
})
891+
expect(single.docs).toHaveLength(1)
892+
893+
const many = await payload.find({
894+
collection: 'text-id-categories-versions' as never,
895+
draft: true,
896+
sort: 'relatedMany',
897+
})
898+
expect(many.docs).toHaveLength(1)
899+
900+
await payload.delete({ collection: 'text-id-posts' as never, where: {} })
901+
await payload.delete({ collection: 'text-id-categories-versions' as never, where: {} })
902+
})
869903
})
870904

871905
describe('REST', () => {

‎test/joins/shared.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export const categoriesVersionsSlug = 'categories-versions'
2424

2525
export const versionsSlug = 'versions'
2626

27+
export const textIdCategoriesVersionsSlug = 'text-id-categories-versions'
28+
29+
export const textIdPostsSlug = 'text-id-posts'
30+
2731
export const collectionSlugs = [
2832
categoriesSlug,
2933
categoriesVersionsSlug,

0 commit comments

Comments
 (0)