fix: querying by polymorphic join field relationTo with overrideAccess: false (#11999)
Previously, querying by polymorphic joins `relationTo` with `overrideAccess: false` caused an error: ``` QueryError: The following paths cannot be queried: relationTo ``` As this field actually doesn't exist in the schema. Now, under condition that the query comes from a polymorphic join we skip checking `relationTo` field access.
This commit is contained in:
@@ -222,6 +222,7 @@ export default buildConfigWithDefaults({
|
||||
},
|
||||
{
|
||||
slug: 'multiple-collections-parents',
|
||||
access: { read: () => true },
|
||||
fields: [
|
||||
{
|
||||
type: 'join',
|
||||
@@ -236,6 +237,7 @@ export default buildConfigWithDefaults({
|
||||
},
|
||||
{
|
||||
slug: 'multiple-collections-1',
|
||||
access: { read: () => true },
|
||||
admin: { useAsTitle: 'title' },
|
||||
fields: [
|
||||
{
|
||||
@@ -255,6 +257,7 @@ export default buildConfigWithDefaults({
|
||||
},
|
||||
{
|
||||
slug: 'multiple-collections-2',
|
||||
access: { read: () => true },
|
||||
admin: { useAsTitle: 'title' },
|
||||
fields: [
|
||||
{
|
||||
|
||||
@@ -1389,7 +1389,7 @@ describe('Joins Field', () => {
|
||||
expect(parent.children?.docs).toHaveLength(1)
|
||||
expect(parent.children.docs[0]?.value.title).toBe('doc-1')
|
||||
|
||||
// WHERE by _relationTo (join for specific collectionSlug)
|
||||
// WHERE by relationTo (join for specific collectionSlug)
|
||||
parent = await payload.findByID({
|
||||
collection: 'multiple-collections-parents',
|
||||
id: parent.id,
|
||||
@@ -1405,6 +1405,23 @@ describe('Joins Field', () => {
|
||||
},
|
||||
})
|
||||
|
||||
// WHERE by relationTo with overrideAccess:false
|
||||
parent = await payload.findByID({
|
||||
collection: 'multiple-collections-parents',
|
||||
id: parent.id,
|
||||
overrideAccess: false,
|
||||
depth: 1,
|
||||
joins: {
|
||||
children: {
|
||||
where: {
|
||||
relationTo: {
|
||||
equals: 'multiple-collections-2',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(parent.children?.docs).toHaveLength(1)
|
||||
expect(parent.children.docs[0]?.value.title).toBe('doc-2')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user