File tree Expand file tree Collapse file tree 4 files changed +48
-1
lines changed
packages/payload/src/fields/config Expand file tree Collapse file tree 4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -200,7 +200,10 @@ export const sanitizeFields = async ({
200
200
}
201
201
202
202
if ( field . type === 'array' && field . fields ) {
203
- field . fields . push ( baseIDField )
203
+ const hasCustomID = field . fields . some ( ( f ) => 'name' in f && f . name === 'id' )
204
+ if ( ! hasCustomID ) {
205
+ field . fields . push ( baseIDField )
206
+ }
204
207
}
205
208
206
209
if ( ( field . type === 'blocks' || field . type === 'array' ) && field . label ) {
Original file line number Diff line number Diff line change @@ -260,6 +260,23 @@ const ArrayFields: CollectionConfig = {
260
260
} ,
261
261
] ,
262
262
} ,
263
+ {
264
+ name : 'arrayWithCustomID' ,
265
+ type : 'array' ,
266
+ fields : [
267
+ {
268
+ name : 'id' ,
269
+ type : 'text' ,
270
+ admin : {
271
+ disableListFilter : true ,
272
+ } ,
273
+ } ,
274
+ {
275
+ name : 'text' ,
276
+ type : 'text' ,
277
+ } ,
278
+ ] ,
279
+ } ,
263
280
] ,
264
281
slug : arrayFieldsSlug ,
265
282
versions : true ,
Original file line number Diff line number Diff line change @@ -2068,6 +2068,21 @@ describe('Fields', () => {
2068
2068
} ) ,
2069
2069
) . rejects . toThrow ( 'The following field is invalid: Items 1 > Sub Array 1 > Text In Row' )
2070
2070
} )
2071
+
2072
+ it ( 'should not have multiple instances of the id field in an array with a nested custom id field' , ( ) => {
2073
+ const arraysCollection = payload . config . collections . find (
2074
+ ( collection ) => collection . slug === arrayFieldsSlug ,
2075
+ )
2076
+
2077
+ const arrayWithNestedCustomIDField = arraysCollection ?. fields . find (
2078
+ ( f ) => f . name === 'arrayWithCustomID' ,
2079
+ )
2080
+
2081
+ const idFields = arrayWithNestedCustomIDField ?. fields . filter ( ( f ) => f . name === 'id' )
2082
+
2083
+ expect ( idFields ) . toHaveLength ( 1 )
2084
+ expect ( idFields [ 0 ] . admin ?. disableListFilter ) . toBe ( true )
2085
+ } )
2071
2086
} )
2072
2087
2073
2088
describe ( 'group' , ( ) => {
Original file line number Diff line number Diff line change @@ -355,6 +355,12 @@ export interface ArrayField {
355
355
id ?: string | null ;
356
356
} [ ]
357
357
| null ;
358
+ arrayWithCustomID ?:
359
+ | {
360
+ id ?: string | null ;
361
+ text ?: string | null ;
362
+ } [ ]
363
+ | null ;
358
364
updatedAt : string ;
359
365
createdAt : string ;
360
366
}
@@ -1977,6 +1983,12 @@ export interface ArrayFieldsSelect<T extends boolean = true> {
1977
1983
text ?: T ;
1978
1984
id ?: T ;
1979
1985
} ;
1986
+ arrayWithCustomID ?:
1987
+ | T
1988
+ | {
1989
+ id ?: T ;
1990
+ text ?: T ;
1991
+ } ;
1980
1992
updatedAt ?: T ;
1981
1993
createdAt ?: T ;
1982
1994
}
You can’t perform that action at this time.
0 commit comments