citusdata / citusdata/activerecord-multi-tenant
`Model.limit(n).delete_all` & `Model.limit(n).update_all` generates incorrect query
- Dominant language
- Ruby
- Stars
- 759
- Forks
- 113
- PR merge metrics
- No merged PRs in 30d
Description
Sharing the queries so it is clear what is happening
`MultiTenant.with(Account.find(1)) { Project.limit(1).delete_all }` generates a SQL query
`DELETE FROM "projects" WHERE "projects"."id" IN (SELECT "projects"."id" FROM "projects" WHERE "projects"."account_id" = 1 AND "projects"."account_id" = 1 LIMIT 1)`
As you can see subquery has account_id condition added correctly but once it returns ids, top level query doesnt have account_id condition.
Ideally it should have generated
`DELETE FROM "projects" WHERE "projects"."id" IN (SELECT "projects"."id" FROM "projects" WHERE "projects"."account_id" = 1 LIMIT 1) AND "projects"."account_id" = 1`
Environment
Rails 6.1
Ruby 3.1
Citus 10.2
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.