fix(db-postgres): alias already in use in this query (#8823)
Fixes https://github.com/payloadcms/payload/issues/8517 Reuses existing joins instead of adding new, duplicate ones which causes: ``` Error: Alias "" is already used in this query. ```
This commit is contained in:
@@ -23,6 +23,10 @@ const ArrayFields: CollectionConfig = {
|
||||
type: 'text',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'anotherText',
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'localizedText',
|
||||
type: 'text',
|
||||
|
||||
@@ -1546,6 +1546,50 @@ describe('Fields', () => {
|
||||
expect(allLocales.localized.en[0].text).toStrictEqual(enText)
|
||||
expect(allLocales.localized.es[0].text).toStrictEqual(esText)
|
||||
})
|
||||
|
||||
it('should query by the same array', async () => {
|
||||
const doc = await payload.create({
|
||||
collection,
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
localizedText: 'test',
|
||||
text: 'required',
|
||||
anotherText: 'another',
|
||||
},
|
||||
],
|
||||
localized: [{ text: 'a' }],
|
||||
},
|
||||
})
|
||||
|
||||
// left join collection_items + left join collection_items_locales
|
||||
const {
|
||||
docs: [res],
|
||||
} = await payload.find({
|
||||
collection,
|
||||
where: {
|
||||
and: [
|
||||
{
|
||||
'items.localizedText': {
|
||||
equals: 'test',
|
||||
},
|
||||
},
|
||||
{
|
||||
'items.anotherText': {
|
||||
equals: 'another',
|
||||
},
|
||||
},
|
||||
{
|
||||
'items.text': {
|
||||
equals: 'required',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
expect(res.id).toBe(doc.id)
|
||||
})
|
||||
})
|
||||
|
||||
describe('group', () => {
|
||||
|
||||
@@ -353,6 +353,7 @@ export interface ArrayField {
|
||||
title?: string | null;
|
||||
items: {
|
||||
text: string;
|
||||
anotherText?: string | null;
|
||||
localizedText?: string | null;
|
||||
subArray?:
|
||||
| {
|
||||
|
||||
Reference in New Issue
Block a user