Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Set _after_create_counter_called flag to make update counter cache work

  • Loading branch information...
commit 5e32f976928e30da6d2017b415657950adf0c2a8 1 parent 7e28b4e
@byroot byroot authored
Showing with 6 additions and 1 deletion.
  1. +6 −1 activerecord/lib/active_record/counter_cache.rb
View
7 activerecord/lib/active_record/counter_cache.rb
@@ -134,7 +134,12 @@ def clear_destroy_state
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
Please sign in to comment.
Something went wrong with that request. Please try again.