Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search and sort by localized field does not work: Error: Alias "XXX_locales" is already used in this query #7015

Open
lazidoca opened this issue Jul 3, 2024 · 2 comments
Labels
status: needs-triage Possible bug which hasn't been reproduced yet v3

Comments

@lazidoca
Copy link

lazidoca commented Jul 3, 2024

Link to reproduction

No response

Payload Version

3.0.0-beta.57

Node Version

20 lts

Next.js Version

15 rc 0

Describe the Bug

I have a posts collection with a localized title field. In the Admin panel, I want to filter by the title. It works if the sortby is unset (it will sort by posts.id I think). If I sort by the title, the error occurs:

Error: Alias "posts_locales" is already used in this query

Reproduction Steps

  1. Create a posts collection with a localized title field
  2. go to /admin/collections/posts
  3. create a post record
  4. enter to the search text input to filter by "title"
  5. Sort by title

Adapters and Plugins

postgresAdapter using node-postgres driver

@lazidoca lazidoca added status: needs-triage Possible bug which hasn't been reproduced yet v3 labels Jul 3, 2024
@lazidoca lazidoca changed the title Search and sort by localized field does not work Search and sort by localized field does not work: Error: Alias "XXX_locales" is already used in this query Jul 3, 2024
@lazidoca
Copy link
Author

lazidoca commented Jul 3, 2024

It seems like when there are multiple joins on the the same table, the chainedMethods is pushed with a new left join which causes the issue:

https://github.com/payloadcms/payload/blob/93bdc0e98d5541fddfe5a143e5678164692d3d37/packages/db-postgres/src/queries/selectDistinct.ts#L37C1-L43C1

@lazidoca
Copy link
Author

lazidoca commented Jul 3, 2024

Payload 3.0 beta 56 works fine, so I think the recent changes in beta 57 causes the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet v3
Projects
None yet
Development

No branches or pull requests

1 participant