From 5e32f976928e30da6d2017b415657950adf0c2a8 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 15 Apr 2014 13:35:02 -0400 Subject: Set _after_create_counter_called flag to make update counter cache work --- activerecord/lib/active_record/counter_cache.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') 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 -- cgit v1.2.3