Skip to content

Commit 1c851b8

Browse files
committed
remove need for :all symbol
Refactor delete_count method to only handle delete_all or nullify/nil cases and not destroy and switch to if/else rather than case statement. This refactoring allows removal of :all symbol usage.
1 parent d8ae276 commit 1c851b8

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

activerecord/lib/active_record/associations/has_many_association.rb

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,35 +105,28 @@ def inverse_updates_counter_cache?(reflection = reflection())
105105
}
106106
end
107107

108-
def delete_count(records, method, scope)
109-
case method
110-
when :destroy
111-
records.length
112-
when :delete_all
108+
def delete_count(method, scope)
109+
if method == :delete_all
113110
scope.delete_all
114111
else
115112
scope.update_all(reflection.foreign_key => nil)
116113
end
117114
end
118115

119116
def delete_all_records(method)
120-
scope = self.scope
121-
122-
count = delete_count(:all, method, scope)
123-
117+
count = delete_count(method, self.scope)
124118
update_counter(-count)
125119
end
126120

127121
# Deletes the records according to the <tt>:dependent</tt> option.
128122
def delete_records(records, method)
129-
scope = self.scope.where(reflection.klass.primary_key => records)
130-
131-
count = delete_count(records, method, scope)
132-
133123
if method == :destroy
124+
count = records.length
134125
records.each(&:destroy!)
135126
update_counter(-count) unless inverse_updates_counter_cache?
136127
else
128+
scope = self.scope.where(reflection.klass.primary_key => records)
129+
count = delete_count(method, scope)
137130
update_counter(-count)
138131
end
139132
end

0 commit comments

Comments
 (0)