aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2014-05-12 14:01:19 -0400
committereileencodes <eileencodes@gmail.com>2014-05-13 20:56:33 -0400
commit1c851b8cdfba73066b4d6c045d9d228647635f98 (patch)
tree39aaf5e261881f5ee9809244d016d7d65834ae68
parentd8ae2764d08ef6474eee978ce03ffb83ab49c6e1 (diff)
downloadrails-1c851b8cdfba73066b4d6c045d9d228647635f98.tar.gz
rails-1c851b8cdfba73066b4d6c045d9d228647635f98.tar.bz2
rails-1c851b8cdfba73066b4d6c045d9d228647635f98.zip
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.
-rw-r--r--activerecord/lib/active_record/associations/has_many_association.rb19
1 files changed, 6 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb
index eed6b0d952..8da543f3ff 100644
--- a/activerecord/lib/active_record/associations/has_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_association.rb
@@ -105,11 +105,8 @@ module ActiveRecord
}
end
- def delete_count(records, method, scope)
- case method
- when :destroy
- records.length
- when :delete_all
+ def delete_count(method, scope)
+ if method == :delete_all
scope.delete_all
else
scope.update_all(reflection.foreign_key => nil)
@@ -117,23 +114,19 @@ module ActiveRecord
end
def delete_all_records(method)
- scope = self.scope
-
- count = delete_count(:all, method, scope)
-
+ count = delete_count(method, self.scope)
update_counter(-count)
end
# Deletes the records according to the <tt>:dependent</tt> option.
def delete_records(records, method)
- scope = self.scope.where(reflection.klass.primary_key => records)
-
- count = delete_count(records, method, scope)
-
if method == :destroy
+ count = records.length
records.each(&:destroy!)
update_counter(-count) unless inverse_updates_counter_cache?
else
+ scope = self.scope.where(reflection.klass.primary_key => records)
+ count = delete_count(method, scope)
update_counter(-count)
end
end