File tree 5 files changed +34
-1
lines changed
packages/payload/src/database
5 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ type Args = {
13
13
errors ?: { path : string } [ ]
14
14
overrideAccess : boolean
15
15
policies ?: EntityPolicies
16
+ polymorphicJoin ?: boolean
16
17
req : PayloadRequest
17
18
versionFields ?: FlattenedField [ ]
18
19
where : Where
@@ -52,6 +53,7 @@ export async function validateQueryPaths({
52
53
collections : { } ,
53
54
globals : { } ,
54
55
} ,
56
+ polymorphicJoin,
55
57
req,
56
58
versionFields,
57
59
where,
@@ -77,6 +79,7 @@ export async function validateQueryPaths({
77
79
overrideAccess,
78
80
path,
79
81
policies,
82
+ polymorphicJoin,
80
83
req,
81
84
val,
82
85
versionFields,
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ type Args = {
21
21
parentIsLocalized ?: boolean
22
22
path : string
23
23
policies : EntityPolicies
24
+ polymorphicJoin ?: boolean
24
25
req : PayloadRequest
25
26
val : unknown
26
27
versionFields ?: FlattenedField [ ]
@@ -39,6 +40,7 @@ export async function validateSearchParam({
39
40
parentIsLocalized,
40
41
path : incomingPath ,
41
42
policies,
43
+ polymorphicJoin,
42
44
req,
43
45
val,
44
46
versionFields,
@@ -102,6 +104,10 @@ export async function validateSearchParam({
102
104
errors . push ( { path } )
103
105
}
104
106
107
+ if ( polymorphicJoin && path === 'relationTo' ) {
108
+ return
109
+ }
110
+
105
111
if ( ! overrideAccess && fieldAffectsData ( field ) ) {
106
112
if ( collectionSlug ) {
107
113
if ( ! policies . collections [ collectionSlug ] ) {
@@ -140,8 +146,10 @@ export async function validateSearchParam({
140
146
const segments = fieldPath . split ( '.' )
141
147
142
148
let fieldAccess
149
+
143
150
if ( versionFields ) {
144
151
fieldAccess = policies [ entityType ] [ entitySlug ]
152
+
145
153
if ( segments [ 0 ] === 'parent' || segments [ 0 ] === 'version' ) {
146
154
segments . shift ( )
147
155
}
Original file line number Diff line number Diff line change 1
1
// @ts -strict-ignore
2
2
import type { SanitizedCollectionConfig , SanitizedJoin } from '../collections/config/types.js'
3
+ import type { FlattenedField } from '../fields/config/types.js'
3
4
import type { JoinQuery , PayloadRequest } from '../types/index.js'
4
5
5
6
import executeAccess from '../auth/executeAccess.js'
@@ -67,6 +68,7 @@ const sanitizeJoinFieldQuery = async ({
67
68
collectionConfig : joinCollectionConfig ,
68
69
errors,
69
70
overrideAccess,
71
+ polymorphicJoin : Array . isArray ( join . field . collection ) ,
70
72
req,
71
73
// incoming where input, but we shouldn't validate generated from the access control.
72
74
where : joinQuery . where ,
Original file line number Diff line number Diff line change @@ -222,6 +222,7 @@ export default buildConfigWithDefaults({
222
222
} ,
223
223
{
224
224
slug : 'multiple-collections-parents' ,
225
+ access : { read : ( ) => true } ,
225
226
fields : [
226
227
{
227
228
type : 'join' ,
@@ -236,6 +237,7 @@ export default buildConfigWithDefaults({
236
237
} ,
237
238
{
238
239
slug : 'multiple-collections-1' ,
240
+ access : { read : ( ) => true } ,
239
241
admin : { useAsTitle : 'title' } ,
240
242
fields : [
241
243
{
@@ -255,6 +257,7 @@ export default buildConfigWithDefaults({
255
257
} ,
256
258
{
257
259
slug : 'multiple-collections-2' ,
260
+ access : { read : ( ) => true } ,
258
261
admin : { useAsTitle : 'title' } ,
259
262
fields : [
260
263
{
Original file line number Diff line number Diff line change @@ -1389,7 +1389,7 @@ describe('Joins Field', () => {
1389
1389
expect ( parent . children ?. docs ) . toHaveLength ( 1 )
1390
1390
expect ( parent . children . docs [ 0 ] ?. value . title ) . toBe ( 'doc-1' )
1391
1391
1392
- // WHERE by _relationTo (join for specific collectionSlug)
1392
+ // WHERE by relationTo (join for specific collectionSlug)
1393
1393
parent = await payload . findByID ( {
1394
1394
collection : 'multiple-collections-parents' ,
1395
1395
id : parent . id ,
@@ -1405,6 +1405,23 @@ describe('Joins Field', () => {
1405
1405
} ,
1406
1406
} )
1407
1407
1408
+ // WHERE by relationTo with overrideAccess:false
1409
+ parent = await payload . findByID ( {
1410
+ collection : 'multiple-collections-parents' ,
1411
+ id : parent . id ,
1412
+ overrideAccess : false ,
1413
+ depth : 1 ,
1414
+ joins : {
1415
+ children : {
1416
+ where : {
1417
+ relationTo : {
1418
+ equals : 'multiple-collections-2' ,
1419
+ } ,
1420
+ } ,
1421
+ } ,
1422
+ } ,
1423
+ } )
1424
+
1408
1425
expect ( parent . children ?. docs ) . toHaveLength ( 1 )
1409
1426
expect ( parent . children . docs [ 0 ] ?. value . title ) . toBe ( 'doc-2' )
1410
1427
You can’t perform that action at this time.
0 commit comments