aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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