fix(db-postgres): querying on array wtihin a relationship field (#8152)
## Description Fixes https://github.com/payloadcms/payload/issues/6037 - [x] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change <!-- Please delete options that are not relevant. --> - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist: - [x] I have added tests that prove my fix is effective or that my feature works - [x] Existing test suite passes locally with my changes
This commit is contained in:
@@ -290,6 +290,31 @@ export default buildConfigWithDefaults({
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
slug: 'pages',
|
||||
fields: [
|
||||
{
|
||||
type: 'array',
|
||||
name: 'menu',
|
||||
fields: [
|
||||
{
|
||||
name: 'label',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
slug: 'rels-to-pages',
|
||||
fields: [
|
||||
{
|
||||
name: 'page',
|
||||
type: 'relationship',
|
||||
relationTo: 'pages',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
onInit: async (payload) => {
|
||||
await payload.create({
|
||||
|
||||
@@ -10,6 +10,7 @@ import type {
|
||||
CustomIdNumberRelation,
|
||||
CustomIdRelation,
|
||||
Director,
|
||||
Page,
|
||||
Post,
|
||||
PostsLocalized,
|
||||
Relation,
|
||||
@@ -676,6 +677,37 @@ describe('Relationships', () => {
|
||||
expect(query.docs).toHaveLength(1)
|
||||
expect(query.docs[0].id).toStrictEqual(firstLevelID)
|
||||
})
|
||||
|
||||
it('should allow querying within array nesting', async () => {
|
||||
const page = await payload.create({
|
||||
collection: 'pages',
|
||||
data: {
|
||||
menu: [
|
||||
{
|
||||
label: 'hello',
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
const rel = await payload.create({ collection: 'rels-to-pages', data: { page: page.id } })
|
||||
|
||||
const resEquals = await payload.find({
|
||||
collection: 'rels-to-pages',
|
||||
where: { 'page.menu.label': { equals: 'hello' } },
|
||||
})
|
||||
|
||||
expect(resEquals.totalDocs).toBe(1)
|
||||
expect(resEquals.docs[0].id).toBe(rel.id)
|
||||
|
||||
const resIn = await payload.find({
|
||||
collection: 'rels-to-pages',
|
||||
where: { 'page.menu.label': { in: ['hello'] } },
|
||||
})
|
||||
|
||||
expect(resIn.totalDocs).toBe(1)
|
||||
expect(resIn.docs[0].id).toBe(rel.id)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Nested Querying Separate Collections', () => {
|
||||
|
||||
@@ -24,6 +24,8 @@ export interface Config {
|
||||
movieReviews: MovieReview;
|
||||
'polymorphic-relationships': PolymorphicRelationship;
|
||||
tree: Tree;
|
||||
pages: Page;
|
||||
'rels-to-pages': RelsToPage;
|
||||
users: User;
|
||||
'payload-preferences': PayloadPreference;
|
||||
'payload-migrations': PayloadMigration;
|
||||
@@ -224,6 +226,31 @@ export interface Tree {
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "pages".
|
||||
*/
|
||||
export interface Page {
|
||||
id: string;
|
||||
menu?:
|
||||
| {
|
||||
label?: string | null;
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "rels-to-pages".
|
||||
*/
|
||||
export interface RelsToPage {
|
||||
id: string;
|
||||
page?: (string | null) | Page;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "payload-preferences".
|
||||
|
||||
Reference in New Issue
Block a user