Skip to content

Commit

Permalink
Merge pull request #340 from masato-bkn/add-redundant-all
Browse files Browse the repository at this point in the history
Add section for redundant `all`
  • Loading branch information
koic authored Aug 26, 2023
2 parents e18585f + 2159845 commit 2e7d125
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 2e7d125

Please sign in to comment.