File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ import {
2121 postsSlug ,
2222 restrictedCategoriesSlug ,
2323 restrictedPostsSlug ,
24+ textIdCategoriesVersionsSlug ,
25+ textIdPostsSlug ,
2426} from './shared.js'
2527
2628const 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 : [
Original file line number Diff line number Diff 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' , ( ) => {
Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ export const categoriesVersionsSlug = 'categories-versions'
2424
2525export const versionsSlug = 'versions'
2626
27+ export const textIdCategoriesVersionsSlug = 'text-id-categories-versions'
28+
29+ export const textIdPostsSlug = 'text-id-posts'
30+
2731export const collectionSlugs = [
2832 categoriesSlug ,
2933 categoriesVersionsSlug ,
You can’t perform that action at this time.
0 commit comments