aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/counter_cache.rb
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2014-04-15 13:35:02 -0400
committerJean Boussier <jean.boussier@gmail.com>2014-04-15 13:54:04 -0400
commit5e32f976928e30da6d2017b415657950adf0c2a8 (patch)
tree3c2602a6f40ccbfdfbede921db1adf83c7a114ab /activerecord/lib/active_record/counter_cache.rb
parent7e28b4ed9a1dbd131877cf784aad7ace49073a52 (diff)
downloadrails-5e32f976928e30da6d2017b415657950adf0c2a8.tar.gz
rails-5e32f976928e30da6d2017b415657950adf0c2a8.tar.bz2
rails-5e32f976928e30da6d2017b415657950adf0c2a8.zip
Set _after_create_counter_called flag to make update counter cache work
Diffstat (limited to 'activerecord/lib/active_record/counter_cache.rb')
-rw-r--r--activerecord/lib/active_record/counter_cache.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb
index 1872d0c141..4108b46439 100644
--- a/activerecord/lib/active_record/counter_cache.rb
+++ b/activerecord/lib/active_record/counter_cache.rb
@@ -134,7 +134,12 @@ module ActiveRecord
def _create_record(*)
id = super
- each_counter_cached_associations(&:increment_counters)
+ each_counter_cached_associations do |association|
+ if record = send(association.reflection.name)
+ association.increment_counters
+ @_after_create_counter_called = true
+ end
+ end
id
end