File tree Expand file tree Collapse file tree 5 files changed +91
-2
lines changed Expand file tree Collapse file tree 5 files changed +91
-2
lines changed Original file line number Diff line number Diff line change @@ -460,7 +460,12 @@ export const transform = ({
460
460
data . globalType = globalSlug
461
461
}
462
462
463
- const sanitize : TraverseFieldsCallback = ( { field, parentPath, ref : incomingRef } ) => {
463
+ const sanitize : TraverseFieldsCallback = ( {
464
+ field,
465
+ parentIsLocalized,
466
+ parentPath,
467
+ ref : incomingRef ,
468
+ } ) => {
464
469
if ( ! incomingRef || typeof incomingRef !== 'object' ) {
465
470
return
466
471
}
Original file line number Diff line number Diff line change @@ -412,7 +412,7 @@ export const traverseFields = ({
412
412
if (
413
413
fieldShouldBeLocalized ( {
414
414
field,
415
- parentIsLocalized : parentIsLocalized ?? field . localized ?? false ,
415
+ parentIsLocalized : parentIsLocalized ?? false ,
416
416
} )
417
417
) {
418
418
if ( Array . isArray ( currentRef ) ) {
Original file line number Diff line number Diff line change @@ -18,6 +18,30 @@ const LocalizedPosts: CollectionConfig = {
18
18
type : 'text' ,
19
19
localized : true ,
20
20
} ,
21
+ {
22
+ name : 'blocks' ,
23
+ type : 'blocks' ,
24
+ blocks : [
25
+ {
26
+ slug : 'block' ,
27
+ fields : [
28
+ {
29
+ name : 'array' ,
30
+ type : 'array' ,
31
+ localized : true ,
32
+ fields : [
33
+ {
34
+ name : 'relationship' ,
35
+ type : 'relationship' ,
36
+ relationTo : 'posts' ,
37
+ localized : true ,
38
+ } ,
39
+ ] ,
40
+ } ,
41
+ ] ,
42
+ } ,
43
+ ] ,
44
+ } ,
21
45
] ,
22
46
}
23
47
Original file line number Diff line number Diff line change @@ -365,6 +365,37 @@ describe('Versions', () => {
365
365
// When creating new version - updatedAt should match version.updatedAt
366
366
expect ( fromNonVersionsTable . updatedAt ) . toBe ( latestVersionData . version . updatedAt )
367
367
} )
368
+
369
+ it ( 'should allow to create with a localized relationships inside a localized array and a block' , async ( ) => {
370
+ const post = await payload . create ( { collection : 'posts' , data : { } } )
371
+ global . d = true
372
+ const res = await payload . create ( {
373
+ collection : 'localized-posts' ,
374
+ draft : true ,
375
+ depth : 0 ,
376
+ data : {
377
+ blocks : [
378
+ {
379
+ blockType : 'block' ,
380
+ array : [
381
+ {
382
+ relationship : post . id ,
383
+ } ,
384
+ ] ,
385
+ } ,
386
+ ] ,
387
+ } ,
388
+ } )
389
+ expect ( res . blocks [ 0 ] ?. array [ 0 ] ?. relationship ) . toEqual ( post . id )
390
+ const {
391
+ docs : [ resFromVersions ] ,
392
+ } = await payload . findVersions ( {
393
+ collection : 'localized-posts' ,
394
+ where : { parent : { equals : res . id } } ,
395
+ depth : 0 ,
396
+ } )
397
+ expect ( resFromVersions ?. version . blocks [ 0 ] ?. array [ 0 ] ?. relationship ) . toEqual ( post . id )
398
+ } )
368
399
} )
369
400
370
401
describe ( 'Restore' , ( ) => {
Original file line number Diff line number Diff line change @@ -360,6 +360,19 @@ export interface LocalizedPost {
360
360
id : string ;
361
361
text ?: string | null ;
362
362
description ?: string | null ;
363
+ blocks ?:
364
+ | {
365
+ array ?:
366
+ | {
367
+ relationship ?: ( string | null ) | Post ;
368
+ id ?: string | null ;
369
+ } [ ]
370
+ | null ;
371
+ id ?: string | null ;
372
+ blockName ?: string | null ;
373
+ blockType : 'block' ;
374
+ } [ ]
375
+ | null ;
363
376
updatedAt : string ;
364
377
createdAt : string ;
365
378
_status ?: ( 'draft' | 'published' ) | null ;
@@ -968,6 +981,22 @@ export interface ErrorOnUnpublishSelect<T extends boolean = true> {
968
981
export interface LocalizedPostsSelect < T extends boolean = true > {
969
982
text ?: T ;
970
983
description ?: T ;
984
+ blocks ?:
985
+ | T
986
+ | {
987
+ block ?:
988
+ | T
989
+ | {
990
+ array ?:
991
+ | T
992
+ | {
993
+ relationship ?: T ;
994
+ id ?: T ;
995
+ } ;
996
+ id ?: T ;
997
+ blockName ?: T ;
998
+ } ;
999
+ } ;
971
1000
updatedAt ?: T ;
972
1001
createdAt ?: T ;
973
1002
_status ?: T ;
You can’t perform that action at this time.
0 commit comments