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

QueryBuilder breaks when where() comes before update() #2390

Closed
parisholley opened this issue Nov 10, 2021 · 1 comment
Closed

QueryBuilder breaks when where() comes before update() #2390

parisholley opened this issue Nov 10, 2021 · 1 comment

Comments

@parisholley
Copy link
Contributor

Describe the bug

error: update "user" set "foobar" = '1' where "e0"."foobar" is null and "e0"."id" in ('1') - missing FROM-clause entry for table "e0"

broken

await em
  .createQueryBuilder(User)
  .where({ foobar: null, id: { $in: userIds } })
  .update({ foobar: member.id })
  .execute();

works

await em
  .createQueryBuilder(User)
  .update({ foobar: member.id })
  .where({ foobar: null, id: { $in: userIds } })
  .execute();

Versions

    "@mikro-orm/cli": "^4.5.9",
    "@mikro-orm/core": "^4.5.9",
    "@mikro-orm/migrations": "^4.5.9",
    "@mikro-orm/nestjs": "^4.3.1",
    "@mikro-orm/postgresql": "^4.5.9",
    "@mikro-orm/reflection": "^4.5.9",
@B4nan
Copy link
Member

B4nan commented Nov 21, 2021

This particular case is working fine in master/v5, no plans to backport as it was fixed by a side effect, so I don't even know where to look for. Issues with this approach are there only when auto-joining comes to play - you can use deep conditions in update/delete and it will generate query with subselect to allow joining - but to do that we need to know the query type before applying the conditions, as that is where auto-joining happens.

Will at least add a validation for that case, as it is easy to validate (calling update/delete on a QB instance that already has some joins).

edit: Actually not, when I use the very same query as you do, with IN clause for PK, it adds the aliases, I guess I will just forbid calling update() after where() for all cases. I did try to implemented lazy processing of the queries, but everything is so tightly coupled that I had to surrender...

@B4nan B4nan closed this as completed in 96893e0 Nov 21, 2021
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