From 834e5336a5d8a8250251e756385e39ebfb4917c3 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Fri, 17 Dec 2010 20:54:50 +0000 Subject: has_many associations with :dependent => :delete_all should update the counter cache when deleting records --- activerecord/lib/active_record/associations/has_many_association.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index bb9dfd4f70..2e99177af4 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -72,8 +72,10 @@ module ActiveRecord with_scope(@scope) do @reflection.klass.update_all(updates, conditions) end + end - @owner.class.update_counters(@owner.id, cached_counter_attribute_name => -records.size) if has_cached_counter? + if has_cached_counter? && @reflection.options[:dependent] != :destroy + @owner.class.update_counters(@owner.id, cached_counter_attribute_name => -records.size) end end -- cgit v1.2.3