Skip to content

Commit

Permalink
Add section for redundant all
Browse files Browse the repository at this point in the history
Co-authored-by: Koichi ITO <[email protected]>
  • Loading branch information
masato-bkn and koic committed Aug 21, 2023
1 parent e18585f commit 2159845
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,26 @@ 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 2159845

Please sign in to comment.