fix(db-mongodb): localized arrays inside blocks with versions (#13804)
Fixes https://github.com/payloadcms/payload/issues/13745
This commit is contained in:
@@ -460,7 +460,12 @@ export const transform = ({
|
|||||||
data.globalType = globalSlug
|
data.globalType = globalSlug
|
||||||
}
|
}
|
||||||
|
|
||||||
const sanitize: TraverseFieldsCallback = ({ field, parentPath, ref: incomingRef }) => {
|
const sanitize: TraverseFieldsCallback = ({
|
||||||
|
field,
|
||||||
|
parentIsLocalized,
|
||||||
|
parentPath,
|
||||||
|
ref: incomingRef,
|
||||||
|
}) => {
|
||||||
if (!incomingRef || typeof incomingRef !== 'object') {
|
if (!incomingRef || typeof incomingRef !== 'object') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -412,7 +412,7 @@ export const traverseFields = ({
|
|||||||
if (
|
if (
|
||||||
fieldShouldBeLocalized({
|
fieldShouldBeLocalized({
|
||||||
field,
|
field,
|
||||||
parentIsLocalized: parentIsLocalized ?? field.localized ?? false,
|
parentIsLocalized: parentIsLocalized ?? false,
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
if (Array.isArray(currentRef)) {
|
if (Array.isArray(currentRef)) {
|
||||||
|
|||||||
@@ -18,6 +18,30 @@ const LocalizedPosts: CollectionConfig = {
|
|||||||
type: 'text',
|
type: 'text',
|
||||||
localized: true,
|
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,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -365,6 +365,37 @@ describe('Versions', () => {
|
|||||||
// When creating new version - updatedAt should match version.updatedAt
|
// When creating new version - updatedAt should match version.updatedAt
|
||||||
expect(fromNonVersionsTable.updatedAt).toBe(latestVersionData.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', () => {
|
describe('Restore', () => {
|
||||||
|
|||||||
@@ -360,6 +360,19 @@ export interface LocalizedPost {
|
|||||||
id: string;
|
id: string;
|
||||||
text?: string | null;
|
text?: string | null;
|
||||||
description?: 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;
|
updatedAt: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
_status?: ('draft' | 'published') | null;
|
_status?: ('draft' | 'published') | null;
|
||||||
@@ -968,6 +981,22 @@ export interface ErrorOnUnpublishSelect<T extends boolean = true> {
|
|||||||
export interface LocalizedPostsSelect<T extends boolean = true> {
|
export interface LocalizedPostsSelect<T extends boolean = true> {
|
||||||
text?: T;
|
text?: T;
|
||||||
description?: T;
|
description?: T;
|
||||||
|
blocks?:
|
||||||
|
| T
|
||||||
|
| {
|
||||||
|
block?:
|
||||||
|
| T
|
||||||
|
| {
|
||||||
|
array?:
|
||||||
|
| T
|
||||||
|
| {
|
||||||
|
relationship?: T;
|
||||||
|
id?: T;
|
||||||
|
};
|
||||||
|
id?: T;
|
||||||
|
blockName?: T;
|
||||||
|
};
|
||||||
|
};
|
||||||
updatedAt?: T;
|
updatedAt?: T;
|
||||||
createdAt?: T;
|
createdAt?: T;
|
||||||
_status?: T;
|
_status?: T;
|
||||||
|
|||||||
Reference in New Issue
Block a user