aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder/belongs_to.rb
diff options
context:
space:
mode:
authorTom Kadwill <tomkadwill@gmail.com>2016-04-23 22:14:10 +0100
committerTom Kadwill <tomkadwill@gmail.com>2016-04-28 21:22:26 +0100
commitc3e3577f9d5058382504773bf0d32afa15cb131e (patch)
tree57148ba1d78773b734baf360ee6d4dbaf4b90d31 /activerecord/lib/active_record/associations/builder/belongs_to.rb
parent39144740e8564a4e79e54ecfcd7a4fe8556b63e6 (diff)
downloadrails-c3e3577f9d5058382504773bf0d32afa15cb131e.tar.gz
rails-c3e3577f9d5058382504773bf0d32afa15cb131e.tar.bz2
rails-c3e3577f9d5058382504773bf0d32afa15cb131e.zip
Fix counter_cache double increment bug
Diffstat (limited to 'activerecord/lib/active_record/associations/builder/belongs_to.rb')
-rw-r--r--activerecord/lib/active_record/associations/builder/belongs_to.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb
index 346329c610..3121e70a04 100644
--- a/activerecord/lib/active_record/associations/builder/belongs_to.rb
+++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -33,6 +33,8 @@ module ActiveRecord::Associations::Builder # :nodoc:
if (@_after_create_counter_called ||= false)
@_after_create_counter_called = false
+ elsif (@_after_replace_counter_called ||= false)
+ @_after_replace_counter_called = false
elsif attribute_changed?(foreign_key) && !new_record?
if reflection.polymorphic?
model = attribute(reflection.foreign_type).try(:constantize)