-
Notifications
You must be signed in to change notification settings - Fork 99
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
Fixes Model.limit(n).delete_all generates incorrect query #200
Conversation
|
||
puts "stmt klass: #{stmt.class}" | ||
|
||
if conditions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here stmt is type of Arel::DeleteManager. When I added tenant parameter, the new where criteria appears inside IN statement.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #200 +/- ##
==========================================
+ Coverage 83.31% 84.04% +0.73%
==========================================
Files 15 16 +1
Lines 725 746 +21
==========================================
+ Hits 604 627 +23
+ Misses 121 119 -2 ☔ View full report in Codecov by Sentry. |
* Fix the tenant scoping for delete_all
fc7ad0d
to
60bfde1
Compare
@serprex can I get approval please? |
# Check if the tenant key is present in the model's column names | ||
tenant_condition = table[tenant_key].eq(tenant_id) | ||
# Add the tenant condition to the arel query if it is not already present | ||
unless arel.constraints.any? { |node| node.to_sql.include?(tenant_condition.to_sql) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tenant_condition.to_sql
can be hoisted out of any?
loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Granted, that will cause an unnecessary to_sql
call when arel.constraints.empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current changes may not address Model.limit(n).update_all
. Should we address update_all as well or take it as a separate fix?
@Amit909Singh if you have solution, please address it in another PR |
I implemented a hook to catch and add tenant into for the issue #195, however when adding a new where criteria, if an IN statement exist, the where criteria is being added into the query inside IN query, not in Delete statement.
I'm using Arel::DeleteManager to manipulate the delete statement.