File tree Expand file tree Collapse file tree 5 files changed +90
-4
lines changed
packages/drizzle/src/queries Expand file tree Collapse file tree 5 files changed +90
-4
lines changed Original file line number Diff line number Diff line change @@ -297,11 +297,13 @@ export const getTableColumnFromPath = ({
297
297
`${ tableName } _${ tableNameSuffix } ${ toSnakeCase ( field . name ) } ` ,
298
298
)
299
299
300
+ const arrayParentTable = aliasTable || adapter . tables [ tableName ]
301
+
300
302
constraintPath = `${ constraintPath } ${ field . name } .%.`
301
303
if ( locale && field . localized && adapter . payload . config . localization ) {
302
304
joins . push ( {
303
305
condition : and (
304
- eq ( adapter . tables [ tableName ] . id , adapter . tables [ newTableName ] . _parentID ) ,
306
+ eq ( arrayParentTable . id , adapter . tables [ newTableName ] . _parentID ) ,
305
307
eq ( adapter . tables [ newTableName ] . _locale , locale ) ,
306
308
) ,
307
309
table : adapter . tables [ newTableName ] ,
@@ -315,7 +317,7 @@ export const getTableColumnFromPath = ({
315
317
}
316
318
} else {
317
319
joins . push ( {
318
- condition : eq ( adapter . tables [ tableName ] . id , adapter . tables [ newTableName ] . _parentID ) ,
320
+ condition : eq ( arrayParentTable . id , adapter . tables [ newTableName ] . _parentID ) ,
319
321
table : adapter . tables [ newTableName ] ,
320
322
} )
321
323
}
Original file line number Diff line number Diff line change @@ -54,8 +54,8 @@ export interface UserAuthOperations {
54
54
*/
55
55
export interface Post {
56
56
id : string ;
57
- customClientField ?: string | null ;
58
- customServerField ?: string | null ;
57
+ text ?: string | null ;
58
+ serverTextField ?: string | null ;
59
59
richText ?: {
60
60
root : {
61
61
type : string ;
Original file line number Diff line number Diff line change @@ -290,6 +290,31 @@ export default buildConfigWithDefaults({
290
290
} ,
291
291
] ,
292
292
} ,
293
+ {
294
+ slug : 'pages' ,
295
+ fields : [
296
+ {
297
+ type : 'array' ,
298
+ name : 'menu' ,
299
+ fields : [
300
+ {
301
+ name : 'label' ,
302
+ type : 'text' ,
303
+ } ,
304
+ ] ,
305
+ } ,
306
+ ] ,
307
+ } ,
308
+ {
309
+ slug : 'rels-to-pages' ,
310
+ fields : [
311
+ {
312
+ name : 'page' ,
313
+ type : 'relationship' ,
314
+ relationTo : 'pages' ,
315
+ } ,
316
+ ] ,
317
+ } ,
293
318
] ,
294
319
onInit : async ( payload ) => {
295
320
await payload . create ( {
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import type {
10
10
CustomIdNumberRelation ,
11
11
CustomIdRelation ,
12
12
Director ,
13
+ Page ,
13
14
Post ,
14
15
PostsLocalized ,
15
16
Relation ,
@@ -676,6 +677,37 @@ describe('Relationships', () => {
676
677
expect ( query . docs ) . toHaveLength ( 1 )
677
678
expect ( query . docs [ 0 ] . id ) . toStrictEqual ( firstLevelID )
678
679
} )
680
+
681
+ it ( 'should allow querying within array nesting' , async ( ) => {
682
+ const page = await payload . create ( {
683
+ collection : 'pages' ,
684
+ data : {
685
+ menu : [
686
+ {
687
+ label : 'hello' ,
688
+ } ,
689
+ ] ,
690
+ } ,
691
+ } )
692
+
693
+ const rel = await payload . create ( { collection : 'rels-to-pages' , data : { page : page . id } } )
694
+
695
+ const resEquals = await payload . find ( {
696
+ collection : 'rels-to-pages' ,
697
+ where : { 'page.menu.label' : { equals : 'hello' } } ,
698
+ } )
699
+
700
+ expect ( resEquals . totalDocs ) . toBe ( 1 )
701
+ expect ( resEquals . docs [ 0 ] . id ) . toBe ( rel . id )
702
+
703
+ const resIn = await payload . find ( {
704
+ collection : 'rels-to-pages' ,
705
+ where : { 'page.menu.label' : { in : [ 'hello' ] } } ,
706
+ } )
707
+
708
+ expect ( resIn . totalDocs ) . toBe ( 1 )
709
+ expect ( resIn . docs [ 0 ] . id ) . toBe ( rel . id )
710
+ } )
679
711
} )
680
712
681
713
describe ( 'Nested Querying Separate Collections' , ( ) => {
Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ export interface Config {
24
24
movieReviews : MovieReview ;
25
25
'polymorphic-relationships' : PolymorphicRelationship ;
26
26
tree : Tree ;
27
+ pages : Page ;
28
+ 'rels-to-pages' : RelsToPage ;
27
29
users : User ;
28
30
'payload-preferences' : PayloadPreference ;
29
31
'payload-migrations' : PayloadMigration ;
@@ -224,6 +226,31 @@ export interface Tree {
224
226
updatedAt : string ;
225
227
createdAt : string ;
226
228
}
229
+ /**
230
+ * This interface was referenced by `Config`'s JSON-Schema
231
+ * via the `definition` "pages".
232
+ */
233
+ export interface Page {
234
+ id : string ;
235
+ menu ?:
236
+ | {
237
+ label ?: string | null ;
238
+ id ?: string | null ;
239
+ } [ ]
240
+ | null ;
241
+ updatedAt : string ;
242
+ createdAt : string ;
243
+ }
244
+ /**
245
+ * This interface was referenced by `Config`'s JSON-Schema
246
+ * via the `definition` "rels-to-pages".
247
+ */
248
+ export interface RelsToPage {
249
+ id : string ;
250
+ page ?: ( string | null ) | Page ;
251
+ updatedAt : string ;
252
+ createdAt : string ;
253
+ }
227
254
/**
228
255
* This interface was referenced by `Config`'s JSON-Schema
229
256
* via the `definition` "payload-preferences".
You can’t perform that action at this time.
0 commit comments