fix: join field with the target relationship inside localized array (#10621)

Fixes https://github.com/payloadcms/payload/issues/10356
This commit is contained in:
Sasha
2025-01-21 02:18:26 +02:00
committed by GitHub
parent 46c1b375b8
commit 25a70ab455
8 changed files with 133 additions and 20 deletions

View File

@@ -109,6 +109,12 @@ export const Categories: CollectionConfig = {
collection: 'posts',
on: 'array.category',
},
{
name: 'localizedArrayPosts',
type: 'join',
collection: 'posts',
on: 'localizedArray.category',
},
{
name: 'blocksPosts',
type: 'join',

View File

@@ -104,6 +104,18 @@ export const Posts: CollectionConfig = {
},
],
},
{
name: 'localizedArray',
type: 'array',
localized: true,
fields: [
{
name: 'category',
type: 'relationship',
relationTo: categoriesSlug,
},
],
},
{
name: 'blocks',
type: 'blocks',

View File

@@ -115,6 +115,7 @@ describe('Joins Field', () => {
camelCaseCategory: category.id,
},
array: [{ category: category.id }],
localizedArray: [{ category: category.id }],
blocks: [{ blockType: 'block', category: category.id }],
})
}
@@ -214,6 +215,16 @@ describe('Joins Field', () => {
expect(categoryWithPosts.arrayPosts.docs).toBeDefined()
})
it('should populate joins with localized array relationships', async () => {
const categoryWithPosts = await payload.findByID({
id: category.id,
collection: categoriesSlug,
})
expect(categoryWithPosts.localizedArrayPosts.docs).toBeDefined()
expect(categoryWithPosts.localizedArrayPosts.docs).toHaveLength(10)
})
it('should populate joins with blocks relationships', async () => {
const categoryWithPosts = await payload.findByID({
id: category.id,

View File

@@ -41,6 +41,7 @@ export interface Config {
'group.relatedPosts': 'posts';
'group.camelCasePosts': 'posts';
arrayPosts: 'posts';
localizedArrayPosts: 'posts';
blocksPosts: 'posts';
polymorphic: 'posts';
polymorphics: 'posts';
@@ -199,6 +200,12 @@ export interface Post {
id?: string | null;
}[]
| null;
localizedArray?:
| {
category?: (string | null) | Category;
id?: string | null;
}[]
| null;
blocks?:
| {
category?: (string | null) | Category;
@@ -272,6 +279,10 @@ export interface Category {
docs?: (string | Post)[] | null;
hasNextPage?: boolean | null;
} | null;
localizedArrayPosts?: {
docs?: (string | Post)[] | null;
hasNextPage?: boolean | null;
} | null;
blocksPosts?: {
docs?: (string | Post)[] | null;
hasNextPage?: boolean | null;
@@ -649,6 +660,12 @@ export interface PostsSelect<T extends boolean = true> {
category?: T;
id?: T;
};
localizedArray?:
| T
| {
category?: T;
id?: T;
};
blocks?:
| T
| {
@@ -680,6 +697,7 @@ export interface CategoriesSelect<T extends boolean = true> {
camelCasePosts?: T;
};
arrayPosts?: T;
localizedArrayPosts?: T;
blocksPosts?: T;
polymorphic?: T;
polymorphics?: T;