diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-12-14 10:21:44 -0800 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-12-14 10:21:44 -0800 |
commit | 0b97ffd45df207ececf139352cbcc8836af89b4c (patch) | |
tree | c1a42950d1312335bed4e5d1391d2eac009b6bbf /activerecord/lib/active_record/associations/has_many_through_association.rb | |
parent | 05e9075541f435b579a96a2519ab71ec27ace895 (diff) | |
parent | a765c8426fe39c73cf9f3ad7f8edcf588c01a11d (diff) | |
download | rails-0b97ffd45df207ececf139352cbcc8836af89b4c.tar.gz rails-0b97ffd45df207ececf139352cbcc8836af89b4c.tar.bz2 rails-0b97ffd45df207ececf139352cbcc8836af89b4c.zip |
Merge pull request #8400 from matthewrobertson/has-many-through-counter-cache
Fix for has_many_through counter_cache bug
Counter caches were not being updated properly when replacing
has_many_through relationships.
Diffstat (limited to 'activerecord/lib/active_record/associations/has_many_through_association.rb')
-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 |