aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-05-06 22:22:07 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-05-06 22:44:01 -0300
commitf8c4a31e0b35576c49cad16c12ebae270cdb0690 (patch)
treee6a00b2da92996b90bfb433eb7362da9c129072b /activerecord/lib/active_record/associations
parent0b35a3aacc384a9552832fdf0e5a0f71393ef2d1 (diff)
downloadrails-f8c4a31e0b35576c49cad16c12ebae270cdb0690.tar.gz
rails-f8c4a31e0b35576c49cad16c12ebae270cdb0690.tar.bz2
rails-f8c4a31e0b35576c49cad16c12ebae270cdb0690.zip
Merge pull request #10489 from greenriver/ar_counter_cache_multiple_destroy
Confirm a record has not already been destroyed before decrementing counter cache Conflicts: activerecord/CHANGELOG.md Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/associations/builder/belongs_to.rb
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/builder/belongs_to.rb5
1 files changed, 4 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb
index 1759a41d93..d78717704c 100644
--- a/activerecord/lib/active_record/associations/builder/belongs_to.rb
+++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -34,7 +34,10 @@ module ActiveRecord::Associations::Builder
method_name = "belongs_to_counter_cache_before_destroy_for_#{name}"
mixin.redefine_method(method_name) do
record = send(name)
- record.class.decrement_counter(cache_column, record.id) unless record.nil?
+
+ if record && !self.destroyed?
+ record.class.decrement_counter(cache_column, record.id)
+ end
end
model.before_destroy(method_name)