File tree Expand file tree Collapse file tree 5 files changed +98
-0
lines changed
packages/ui/src/fields/Join Expand file tree Collapse file tree 5 files changed +98
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,10 @@ const getInitialDrawerData = ({
43
43
44
44
const field = flattenedFields . find ( ( field ) => field . name === path )
45
45
46
+ if ( ! field ) {
47
+ return null
48
+ }
49
+
46
50
if ( field . type === 'relationship' || field . type === 'upload' ) {
47
51
return {
48
52
// TODO: Handle polymorphic https://github.com/payloadcms/payload/pull/9990
@@ -71,6 +75,25 @@ const getInitialDrawerData = ({
71
75
[ field . name ] : [ initialData ] ,
72
76
}
73
77
}
78
+
79
+ if ( field . type === 'blocks' ) {
80
+ for ( const block of field . blocks ) {
81
+ const blockInitialData = getInitialDrawerData ( {
82
+ docID,
83
+ fields : block . fields ,
84
+ segments : nextSegments ,
85
+ } )
86
+
87
+ if ( blockInitialData ) {
88
+ blockInitialData . id = ObjectId ( ) . toHexString ( )
89
+ blockInitialData . blockType = block . slug
90
+
91
+ return {
92
+ [ field . name ] : [ blockInitialData ] ,
93
+ }
94
+ }
95
+ }
96
+ }
74
97
}
75
98
76
99
const JoinFieldComponent : JoinFieldClientComponent = ( props ) => {
Original file line number Diff line number Diff line change @@ -109,6 +109,12 @@ export const Categories: CollectionConfig = {
109
109
collection : 'posts' ,
110
110
on : 'array.category' ,
111
111
} ,
112
+ {
113
+ name : 'blocksPosts' ,
114
+ type : 'join' ,
115
+ collection : 'posts' ,
116
+ on : 'blocks.category' ,
117
+ } ,
112
118
{
113
119
name : 'singulars' ,
114
120
type : 'join' ,
Original file line number Diff line number Diff line change @@ -80,5 +80,21 @@ export const Posts: CollectionConfig = {
80
80
} ,
81
81
] ,
82
82
} ,
83
+ {
84
+ name : 'blocks' ,
85
+ type : 'blocks' ,
86
+ blocks : [
87
+ {
88
+ slug : 'block' ,
89
+ fields : [
90
+ {
91
+ name : 'category' ,
92
+ type : 'relationship' ,
93
+ relationTo : categoriesSlug ,
94
+ } ,
95
+ ] ,
96
+ } ,
97
+ ] ,
98
+ } ,
83
99
] ,
84
100
}
Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ describe('Joins Field', () => {
95
95
camelCaseCategory : category . id ,
96
96
} ,
97
97
array : [ { category : category . id } ] ,
98
+ blocks : [ { blockType : 'block' , category : category . id } ] ,
98
99
} )
99
100
}
100
101
} )
@@ -193,6 +194,15 @@ describe('Joins Field', () => {
193
194
expect ( categoryWithPosts . arrayPosts . docs ) . toBeDefined ( )
194
195
} )
195
196
197
+ it ( 'should populate joins with blocks relationships' , async ( ) => {
198
+ const categoryWithPosts = await payload . findByID ( {
199
+ id : category . id ,
200
+ collection : categoriesSlug ,
201
+ } )
202
+
203
+ expect ( categoryWithPosts . blocksPosts . docs ) . toBeDefined ( )
204
+ } )
205
+
196
206
it ( 'should populate uploads in joins' , async ( ) => {
197
207
const { docs } = await payload . find ( {
198
208
limit : 1 ,
Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ export interface Config {
36
36
hasManyPostsLocalized : 'posts' ;
37
37
'group.relatedPosts' : 'posts' ;
38
38
'group.camelCasePosts' : 'posts' ;
39
+ arrayPosts : 'posts' ;
40
+ blocksPosts : 'posts' ;
39
41
filtered : 'posts' ;
40
42
hiddenPosts : 'hidden-posts' ;
41
43
singulars : 'singular' ;
@@ -125,6 +127,20 @@ export interface Post {
125
127
category ?: ( string | null ) | Category ;
126
128
camelCaseCategory ?: ( string | null ) | Category ;
127
129
} ;
130
+ array ?:
131
+ | {
132
+ category ?: ( string | null ) | Category ;
133
+ id ?: string | null ;
134
+ } [ ]
135
+ | null ;
136
+ blocks ?:
137
+ | {
138
+ category ?: ( string | null ) | Category ;
139
+ id ?: string | null ;
140
+ blockName ?: string | null ;
141
+ blockType : 'block' ;
142
+ } [ ]
143
+ | null ;
128
144
updatedAt : string ;
129
145
createdAt : string ;
130
146
}
@@ -183,6 +199,14 @@ export interface Category {
183
199
hasNextPage ?: boolean | null ;
184
200
} | null ;
185
201
} ;
202
+ arrayPosts ?: {
203
+ docs ?: ( string | Post ) [ ] | null ;
204
+ hasNextPage ?: boolean | null ;
205
+ } | null ;
206
+ blocksPosts ?: {
207
+ docs ?: ( string | Post ) [ ] | null ;
208
+ hasNextPage ?: boolean | null ;
209
+ } | null ;
186
210
singulars ?: {
187
211
docs ?: ( string | Singular ) [ ] | null ;
188
212
hasNextPage ?: boolean | null ;
@@ -463,6 +487,23 @@ export interface PostsSelect<T extends boolean = true> {
463
487
category ?: T ;
464
488
camelCaseCategory ?: T ;
465
489
} ;
490
+ array ?:
491
+ | T
492
+ | {
493
+ category ?: T ;
494
+ id ?: T ;
495
+ } ;
496
+ blocks ?:
497
+ | T
498
+ | {
499
+ block ?:
500
+ | T
501
+ | {
502
+ category ?: T ;
503
+ id ?: T ;
504
+ blockName ?: T ;
505
+ } ;
506
+ } ;
466
507
updatedAt ?: T ;
467
508
createdAt ?: T ;
468
509
}
@@ -482,6 +523,8 @@ export interface CategoriesSelect<T extends boolean = true> {
482
523
relatedPosts ?: T ;
483
524
camelCasePosts ?: T ;
484
525
} ;
526
+ arrayPosts ?: T ;
527
+ blocksPosts ?: T ;
485
528
singulars ?: T ;
486
529
filtered ?: T ;
487
530
updatedAt ?: T ;
You can’t perform that action at this time.
0 commit comments