diff options
author | Jon Leighton <j@jonathanleighton.com> | 2010-12-17 20:54:50 +0000 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-20 13:56:04 -0800 |
commit | 834e5336a5d8a8250251e756385e39ebfb4917c3 (patch) | |
tree | 76adf636cd2fe00e272ab77d98fca75f814d0174 /activerecord/lib | |
parent | 57b90098930a52fa160f9b1aed2dcea0f557d670 (diff) | |
download | rails-834e5336a5d8a8250251e756385e39ebfb4917c3.tar.gz rails-834e5336a5d8a8250251e756385e39ebfb4917c3.tar.bz2 rails-834e5336a5d8a8250251e756385e39ebfb4917c3.zip |
has_many associations with :dependent => :delete_all should update the counter cache when deleting records
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_association.rb | 4 |
1 files changed, 3 insertions, 1 deletions
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 |