Skip to content

Commit

Permalink
Add section for redundant all
Browse files Browse the repository at this point in the history
  • Loading branch information
masato-bkn committed Aug 21, 2023
1 parent e18585f commit 8661a42
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,25 @@ User.where.not(status: 'active', plan: 'basic')
User.where.not('status = ? AND plan = ?', 'active', 'basic')
----

=== Redundant `all` [[redundant-all]]
Using `all` as a receiver for Active Record query methods is redundant.
The result won't change without `all`, so it can be removed.

[source, ruby]
----
# bad
User.all.find(id)
User.all.order(:created_at)
users.all.where(id: ids)
user.articles.all.order(:created_at)
# good
User.find(id)
User.order(:created_at)
users.where(id: ids)
user.articles.order(:created_at)
----

== Migrations

=== Schema Version [[schema-version]]
Expand Down

0 comments on commit 8661a42

Please sign in to comment.