diff --git a/packages/db-mongodb/src/utilities/transform.ts b/packages/db-mongodb/src/utilities/transform.ts index 19984f041..42126aedd 100644 --- a/packages/db-mongodb/src/utilities/transform.ts +++ b/packages/db-mongodb/src/utilities/transform.ts @@ -460,7 +460,12 @@ export const transform = ({ data.globalType = globalSlug } - const sanitize: TraverseFieldsCallback = ({ field, parentPath, ref: incomingRef }) => { + const sanitize: TraverseFieldsCallback = ({ + field, + parentIsLocalized, + parentPath, + ref: incomingRef, + }) => { if (!incomingRef || typeof incomingRef !== 'object') { return } diff --git a/packages/payload/src/utilities/traverseFields.ts b/packages/payload/src/utilities/traverseFields.ts index 766accef3..bec49dd83 100644 --- a/packages/payload/src/utilities/traverseFields.ts +++ b/packages/payload/src/utilities/traverseFields.ts @@ -412,7 +412,7 @@ export const traverseFields = ({ if ( fieldShouldBeLocalized({ field, - parentIsLocalized: parentIsLocalized ?? field.localized ?? false, + parentIsLocalized: parentIsLocalized ?? false, }) ) { if (Array.isArray(currentRef)) { diff --git a/test/versions/collections/Localized.ts b/test/versions/collections/Localized.ts index 5653957a5..ad4d7bb67 100644 --- a/test/versions/collections/Localized.ts +++ b/test/versions/collections/Localized.ts @@ -18,6 +18,30 @@ const LocalizedPosts: CollectionConfig = { type: 'text', localized: true, }, + { + name: 'blocks', + type: 'blocks', + blocks: [ + { + slug: 'block', + fields: [ + { + name: 'array', + type: 'array', + localized: true, + fields: [ + { + name: 'relationship', + type: 'relationship', + relationTo: 'posts', + localized: true, + }, + ], + }, + ], + }, + ], + }, ], } diff --git a/test/versions/int.spec.ts b/test/versions/int.spec.ts index f48ccca37..6b853e08f 100644 --- a/test/versions/int.spec.ts +++ b/test/versions/int.spec.ts @@ -365,6 +365,37 @@ describe('Versions', () => { // When creating new version - updatedAt should match version.updatedAt expect(fromNonVersionsTable.updatedAt).toBe(latestVersionData.version.updatedAt) }) + + it('should allow to create with a localized relationships inside a localized array and a block', async () => { + const post = await payload.create({ collection: 'posts', data: {} }) + global.d = true + const res = await payload.create({ + collection: 'localized-posts', + draft: true, + depth: 0, + data: { + blocks: [ + { + blockType: 'block', + array: [ + { + relationship: post.id, + }, + ], + }, + ], + }, + }) + expect(res.blocks[0]?.array[0]?.relationship).toEqual(post.id) + const { + docs: [resFromVersions], + } = await payload.findVersions({ + collection: 'localized-posts', + where: { parent: { equals: res.id } }, + depth: 0, + }) + expect(resFromVersions?.version.blocks[0]?.array[0]?.relationship).toEqual(post.id) + }) }) describe('Restore', () => { diff --git a/test/versions/payload-types.ts b/test/versions/payload-types.ts index df501ec2d..85a865483 100644 --- a/test/versions/payload-types.ts +++ b/test/versions/payload-types.ts @@ -360,6 +360,19 @@ export interface LocalizedPost { id: string; text?: string | null; description?: string | null; + blocks?: + | { + array?: + | { + relationship?: (string | null) | Post; + id?: string | null; + }[] + | null; + id?: string | null; + blockName?: string | null; + blockType: 'block'; + }[] + | null; updatedAt: string; createdAt: string; _status?: ('draft' | 'published') | null; @@ -968,6 +981,22 @@ export interface ErrorOnUnpublishSelect { export interface LocalizedPostsSelect { text?: T; description?: T; + blocks?: + | T + | { + block?: + | T + | { + array?: + | T + | { + relationship?: T; + id?: T; + }; + id?: T; + blockName?: T; + }; + }; updatedAt?: T; createdAt?: T; _status?: T;