Skip to content

Commit 2d0a752

Browse files
authored
Merge pull request #348 from masato-bkn/add-note-to-redundant-all-section
Add note to redundant-all section about `all` receiver being an association
2 parents ee8c5a1 + 7068195 commit 2d0a752

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

README.adoc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,7 @@ User.where.not('status = ? AND plan = ?', 'active', 'basic')
11031103

11041104
=== Redundant `all` [[redundant-all]]
11051105

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.
1106+
Using `all` as a receiver is redundant. The result won't change without `all`, so it should be removed.
11081107

11091108
[source, ruby]
11101109
----
@@ -1121,6 +1120,17 @@ users.where(id: ids)
11211120
user.articles.order(:created_at)
11221121
----
11231122

1123+
NOTE: When the receiver for `all` is an association, there are methods whose behavior changes by omitting `all`.
1124+
1125+
The following methods behave differently without `all`:
1126+
1127+
* `delete` - https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-delete[with all] / https://api.rubyonrails.org/classes/ActiveRecord/Associations/CollectionProxy.html#method-i-delete[without all]
1128+
* `delete_all` - https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-delete_all[with all] / https://api.rubyonrails.org/classes/ActiveRecord/Associations/CollectionProxy.html#method-i-delete_all[without all]
1129+
* `destroy` - https://api.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-destroy[with all] / https://api.rubyonrails.org/classes/ActiveRecord/Associations/CollectionProxy.html#method-i-destroy[without all]
1130+
* `destroy_all` - https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-destroy_all[with all] / https://api.rubyonrails.org/classes/ActiveRecord/Associations/CollectionProxy.html#method-i-destroy_all[without all]
1131+
1132+
So, when considering removing `all` from the receiver of these methods, it is recommended to refer to the documentation to understand how the behavior changes.
1133+
11241134
== Migrations
11251135

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

0 commit comments

Comments
 (0)