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:
Sasha
2024-10-22 17:14:38 +03:00
committed by GitHub
parent 69125504af
commit 4c396c720e
7 changed files with 101 additions and 22 deletions

View File

@@ -23,6 +23,10 @@ const ArrayFields: CollectionConfig = {
type: 'text',
required: true,
},
{
name: 'anotherText',
type: 'text',
},
{
name: 'localizedText',
type: 'text',

View File

@@ -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', () => {

View File

@@ -353,6 +353,7 @@ export interface ArrayField {
title?: string | null;
items: {
text: string;
anotherText?: string | null;
localizedText?: string | null;
subArray?:
| {