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

Invalid SQL query for ManyToMany relations using some, none or every when querying #5301

Closed
5 tasks done
NicklasKnell opened this issue Mar 1, 2024 · 1 comment
Closed
5 tasks done

Comments

@NicklasKnell
Copy link

Describe the bug

Using a query operator like $some, $none or $every on a ManyToMany relation results in an invalid query, if the Entities start with the same Letter.

This error is from the provided reproduction:

select count(*) as "count"
from "user" as "u0"
where
    "u0"."id" in (
        select "u0"."id"
        from
            "user" as "u0"
            left join "user_labels" as "u1" on "u0"."id" = "u1"."user_id"
            inner join "public"."user_label" as "u1" on "u1"."user_label_id" = "u1"."id"
        where
            "u1"."user_label_id" = 1
    )

table name "u1" specified more than once

Reproduction

I used docker compose to start a postgresql instance.
https://github.com/NicklasKnell/reproduction/tree/illegal-query-for-manytomany

When renaming the Entity UserLabel to Label it will work.

What driver are you using?

@mikro-orm/postgresql

MikroORM version

6.1.5

Node.js version

v20.11.0

Operating system

Ubuntu

Validations

@B4nan
Copy link
Member

B4nan commented Mar 1, 2024

I guess I see it, we clone the QB (which resets the alias counter), but then use the original QB instance to get the next alias here.

@B4nan B4nan closed this as completed in 0435faf Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants