diff options
author | Matthew Robertson <matthewrobertson03@gmail.com> | 2012-12-01 17:56:28 -0800 |
---|---|---|
committer | Matthew Robertson <matthew@cloudclinic.ca> | 2012-12-14 10:03:05 -0800 |
commit | a765c8426fe39c73cf9f3ad7f8edcf588c01a11d (patch) | |
tree | 237335100d1015cb7b40f8b8eecc4afa38d78f53 /activerecord/lib/active_record | |
parent | 01d3a36bfe5d56d85f8a36f2fe10ad96662b4530 (diff) | |
download | rails-a765c8426fe39c73cf9f3ad7f8edcf588c01a11d.tar.gz rails-a765c8426fe39c73cf9f3ad7f8edcf588c01a11d.tar.bz2 rails-a765c8426fe39c73cf9f3ad7f8edcf588c01a11d.zip |
Fix for has_many_through counter_cache bug
This commit fixes reported issue #7630 in which counter
caches were not being updated properly when replacing
has_many_through relationships
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index c7d8a84a7e..c3266f2bb4 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -153,6 +153,11 @@ module ActiveRecord delete_through_records(records) + if source_reflection.options[:counter_cache] + counter = source_reflection.counter_cache_column + klass.decrement_counter counter, records.map(&:id) + end + if through_reflection.macro == :has_many && update_through_counter?(method) update_counter(-count, through_reflection) end |