Skip to content

Commit 05a90c3

Browse files
committed
rename delete_all_records to delete_or_nullify_all_records
Rename delete_all_records because this name better describes what the method is doing. We can then remove :all from the hm:t version and pull out the unoptimized call to load_target in delete_records and pass it directly.
1 parent 1c851b8 commit 05a90c3

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

activerecord/lib/active_record/associations/collection_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def delete_all(dependent = nil)
194194
options[:dependent]
195195
end
196196

197-
delete_all_records(dependent).tap do
197+
delete_or_nullify_all_records(dependent).tap do
198198
reset
199199
loaded!
200200
end

activerecord/lib/active_record/associations/has_many_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def delete_count(method, scope)
113113
end
114114
end
115115

116-
def delete_all_records(method)
116+
def delete_or_nullify_all_records(method)
117117
count = delete_count(method, self.scope)
118118
update_counter(-count)
119119
end

activerecord/lib/active_record/associations/has_many_through_association.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,13 @@ def update_through_counter?(method)
130130
end
131131
end
132132

133-
def delete_all_records(method)
134-
delete_records(:all, method)
133+
def delete_or_nullify_all_records(method)
134+
delete_records(load_target, method)
135135
end
136136

137137
def delete_records(records, method)
138138
ensure_not_nested
139139

140-
# This is unoptimised; it will load all the target records
141-
# even when we just want to delete everything.
142-
records = load_target if records == :all
143-
144140
scope = through_association.scope
145141
scope.where! construct_join_attributes(*records)
146142

0 commit comments

Comments
 (0)