Skip to content

Commit 2e7d125

Browse files
authored
Merge pull request #340 from masato-bkn/add-redundant-all
Add section for redundant `all`
2 parents e18585f + 2159845 commit 2e7d125

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.adoc

+20
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,26 @@ User.where.not(status: 'active', plan: 'basic')
11011101
User.where.not('status = ? AND plan = ?', 'active', 'basic')
11021102
----
11031103

1104+
=== Redundant `all` [[redundant-all]]
1105+
1106+
Using `all` as a receiver for Active Record query methods is redundant.
1107+
The result won't change without `all`, so it can be removed.
1108+
1109+
[source, ruby]
1110+
----
1111+
# bad
1112+
User.all.find(id)
1113+
User.all.order(:created_at)
1114+
users.all.where(id: ids)
1115+
user.articles.all.order(:created_at)
1116+
1117+
# good
1118+
User.find(id)
1119+
User.order(:created_at)
1120+
users.where(id: ids)
1121+
user.articles.order(:created_at)
1122+
----
1123+
11041124
== Migrations
11051125

11061126
=== Schema Version [[schema-version]]

0 commit comments

Comments
 (0)