diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-05-06 22:22:07 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-05-06 22:44:01 -0300 |
commit | f8c4a31e0b35576c49cad16c12ebae270cdb0690 (patch) | |
tree | e6a00b2da92996b90bfb433eb7362da9c129072b /activerecord/lib | |
parent | 0b35a3aacc384a9552832fdf0e5a0f71393ef2d1 (diff) | |
download | rails-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')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/belongs_to.rb | 5 |
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) |