-
-
Notifications
You must be signed in to change notification settings - Fork 264
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
Rails/WhereEquals Hash conditions over SQL fragment issue #418
Comments
This looks like an expected behavior. What kind of problem is there? # bad
User.where('name IS NULL')
# good
User.where(name: nil) https://docs.rubocop.org/rubocop-rails/2.9/cops_rails.html#railswhereequals |
One potential issue (and maybe the cop should be not marked as Safe) is that with a string query the DB will match it to any joined column if it's non-ambiguous (ie. |
Hi @koic Thank you for your time and answer!
Well, except that it isn't bad. I agree with Doing a small benchmark: https://gist.github.com/vpereira/797d594d2bd9abfe35ae8bfb5a78cf85 You get the following results:
Probably the performance deterioration comes from the fact that we have to evaluate the hash, construct the query, etc, etc. So switch blindly constant by a variable, IMO, isn't safe. Disable the cop isn't an option for me. Disable it inline is just ok if you have just a few of such entries. Unfortunately not my case. My suggestion would be to split this Cop in two: One cop for dynamic queries using question marks or named bind variables, enabled by default, and |
The autocorrect of this cop should definitely be marked as unsafe. We just ran into an issue where the following was autocorrected
to
which doesn't work, since the |
Fixes rubocop#403 and rubocop#418. This PR marks `Rails/WhereEquals` as unsafe auto-correction.
Fixes rubocop#403 and rubocop#418. This PR marks `Rails/WhereEquals` as unsafe auto-correction.
This issue has been resolved by #403. Thank you. |
Hi rubocop team!
Expected Behavior
Using the cop
Rails/WhereEquals
, constant strings shouldn't get auto corrected to hashThe snippet
where('links_to_id is null')
should not be auto corrected towhere(links_to_id: nil)
Actual Behavior
The cop auto-correct queries without placeholders or interpolation, like
where('links_to_id is null')
The text was updated successfully, but these errors were encountered: