aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-07-24 13:31:28 -0400
committerGitHub <noreply@github.com>2017-07-24 13:31:28 -0400
commitdd58cc2ebb9cc0f4f4db50a1a6d3296ad9a6a8e2 (patch)
treec010db36f87f3cd3720c53877c158b8549e408cb /activerecord/lib
parent501941b10828f274135ec974814ed815e4ffcffa (diff)
parent6137a4e8f77f0bba78d304d962b89ddf3cf465aa (diff)
downloadrails-dd58cc2ebb9cc0f4f4db50a1a6d3296ad9a6a8e2.tar.gz
rails-dd58cc2ebb9cc0f4f4db50a1a6d3296ad9a6a8e2.tar.bz2
rails-dd58cc2ebb9cc0f4f4db50a1a6d3296ad9a6a8e2.zip
Merge pull request #29765 from lugray/fix_counter_cache
Fix `counter_cache` double increment
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/builder/belongs_to.rb4
-rw-r--r--activerecord/lib/active_record/counter_cache.rb1
2 files changed, 1 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb
index 7b303e923b..9904ee4bed 100644
--- a/activerecord/lib/active_record/associations/builder/belongs_to.rb
+++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -34,9 +34,7 @@ module ActiveRecord::Associations::Builder # :nodoc:
foreign_key = reflection.foreign_key
cache_column = reflection.counter_cache_column
- if (@_after_create_counter_called ||= false)
- @_after_create_counter_called = false
- elsif (@_after_replace_counter_called ||= false)
+ if (@_after_replace_counter_called ||= false)
@_after_replace_counter_called = false
elsif saved_change_to_attribute?(foreign_key) && !new_record?
if reflection.polymorphic?
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb
index ab2bfb63a6..5005d58f1c 100644
--- a/activerecord/lib/active_record/counter_cache.rb
+++ b/activerecord/lib/active_record/counter_cache.rb
@@ -182,7 +182,6 @@ module ActiveRecord
each_counter_cached_associations do |association|
if send(association.reflection.name)
association.increment_counters
- @_after_create_counter_called = true
end
end