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
Ignore empty condition on #construct_relation_for_exists #34329
Ignore empty condition on #construct_relation_for_exists #34329
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
This changes the existing How about just fixing diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 6f420fe6bb..55c387f7b7 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -363,7 +363,7 @@ def construct_relation_for_exists(conditions)
case conditions
when Array, Hash
- relation.where!(conditions)
+ relation.where!(conditions) unless condition.empty?
else
relation.where!(primary_key => conditions) unless conditions == :none
end |
Note that |
I agree that we shouldn't change the existent So here we can choose the one of following solutions I think:
The advantage of 2nd option is we can still keep the same behavior on |
I'm not prefer to add extra / duplicated args checking |
Okay, it means it's a special feature of In this case, just fixing |
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.
Looks good to me.
Can you squash your commits and include the context (Summary part in this PR) in the commit message?
ah I realized that 2nd commit includes the context. Please ignore about the commit message. |
At rails@fc0e335, ```rb relation = relation.where(conditions) ``` was rewritten to: ```rb relation.where!(condition) ``` This change accidentally changed the result of `Topic.exists?({})` from true to false. To fix this regression, first I moved the blank check logic (`opts.blank?`) from `#where` to `#where!`, because I thought `#where!` should be identical to `#where`, except that instead of returning a new relation, it adds the condition to the existing relation. But on second thought after some discussion on rails#34329, I started to think that just fixing `#construct_relation_for_exists` is more preferable than changing `#where` and `#where!`.
79e42bd
to
4694fcf
Compare
Squashed the 2 commits into 4694fcf that has all the context of this PR in its commit message. |
Thanks! |
…sistency Ignore empty condition on #construct_relation_for_exists
…sistency Ignore empty condition on #construct_relation_for_exists
Summary
At fc0e335,
was rewritten to:
This change accidentally changed the result of
Topic.exists?({})
from true to false.To fix this regression, I moved the blank check logic (
opts.blank?
) from#where
to#where!
.I think
#where!
should be identical to#where
, except that instead of returning a new relation, it adds the condition to the existing relation.Details
Steps to reproduce
Expected behavior
Actual behavior