-
-
Notifications
You must be signed in to change notification settings - Fork 268
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
Cop idea: AR use none?
/empty?
instead of !exists?
without conditions
#888
Labels
feature request
Request for new functionality
Comments
Note, It can be changed from Model.empty? #=> undefined method `empty?' |
koic
added a commit
to koic/rubocop-rails
that referenced
this issue
Apr 4, 2023
Fixes rubocop#888. This PR makes `Style/InverseMethods` aware of `exists?`. Probably simpler than implementing a new named cop. And there will be no overlap with existing cop as reported in rubocop#941.
9 tasks
koic
added a commit
that referenced
this issue
Apr 4, 2023
…_exists_predicate [Fix #888] Make `Style/InverseMethods` aware of `exists?`
Also: user = User.new
user.posts.new
|
Heads-up
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
A new cop to check for the usage of
none?
instead of!exists?
when no conditions are given.Describe the solution you'd like
The cop should suggest the following change:
This should not be triggered if
exists?
has parameters, becauseempty?
andnone?
do not support argumentsAdditional context
I've tried to read the source code of AR, and it appears that
none?
and!exists?
are not the same, becauseempty?
will avoid an extraSELECT 1 AS one
query if the records are already loadedI've tested if there are performance differences with:
In case the association is not preloaded (same scenario without
includes(:addresses)
), for this use case, the result is the sameThe text was updated successfully, but these errors were encountered: