aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/counter_cache.rb
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2014-04-15 14:11:47 -0400
committerJean Boussier <jean.boussier@gmail.com>2014-04-15 14:11:47 -0400
commitd2543412ff42d64c5fc5d763336b3f3ec9ab8eda (patch)
treeb9dbac957762875389cd7efa72ddf205922820b7 /activerecord/lib/active_record/counter_cache.rb
parent5e32f976928e30da6d2017b415657950adf0c2a8 (diff)
downloadrails-d2543412ff42d64c5fc5d763336b3f3ec9ab8eda.tar.gz
rails-d2543412ff42d64c5fc5d763336b3f3ec9ab8eda.tar.bz2
rails-d2543412ff42d64c5fc5d763336b3f3ec9ab8eda.zip
Restore the destroy_by_association check in post destroy counter cache
Diffstat (limited to 'activerecord/lib/active_record/counter_cache.rb')
-rw-r--r--activerecord/lib/active_record/counter_cache.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb
index 4108b46439..b7b790322a 100644
--- a/activerecord/lib/active_record/counter_cache.rb
+++ b/activerecord/lib/active_record/counter_cache.rb
@@ -135,7 +135,7 @@ module ActiveRecord
id = super
each_counter_cached_associations do |association|
- if record = send(association.reflection.name)
+ if send(association.reflection.name)
association.increment_counters
@_after_create_counter_called = true
end
@@ -148,7 +148,14 @@ module ActiveRecord
affected_rows = super
if affected_rows > 0
- each_counter_cached_associations(&:decrement_counters)
+ each_counter_cached_associations do |association|
+ foreign_key = association.reflection.foreign_key.to_sym
+ unless destroyed_by_association && destroyed_by_association.foreign_key.to_sym == foreign_key
+ if send(association.reflection.name)
+ association.decrement_counters
+ end
+ end
+ end
end
affected_rows