diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-03 14:02:47 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-03 14:02:47 -0800 |
commit | 7985f64e25980369bcf66b326310743cd028dbea (patch) | |
tree | a4be6748d98915d717db77e0e76deebe4b494ad8 /activerecord/lib | |
parent | d1230a8cd0ddcf0497ffe294548549c2ab0bef1c (diff) | |
parent | 5d2bf4d12985ba92079178787ea47d4e3992a747 (diff) | |
download | rails-7985f64e25980369bcf66b326310743cd028dbea.tar.gz rails-7985f64e25980369bcf66b326310743cd028dbea.tar.bz2 rails-7985f64e25980369bcf66b326310743cd028dbea.zip |
Merge pull request #2955 from dmitry/master
Polymorphic with optimistic lock and counter cache should be destroyed
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/belongs_to.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/builder/has_many.rb | 7 |
2 files changed, 5 insertions, 8 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..4183c222de 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -33,8 +33,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? + unless marked_for_destruction? + record = send(name) + record.class.decrement_counter(cache_column, record.id) unless record.nil? + end end model.before_destroy(method_name) diff --git a/activerecord/lib/active_record/associations/builder/has_many.rb b/activerecord/lib/active_record/associations/builder/has_many.rb index 9c24f40690..fc6799fb15 100644 --- a/activerecord/lib/active_record/associations/builder/has_many.rb +++ b/activerecord/lib/active_record/associations/builder/has_many.rb @@ -31,12 +31,7 @@ module ActiveRecord::Associations::Builder mixin.redefine_method(dependency_method_name) do send(name).each do |o| # No point in executing the counter update since we're going to destroy the parent anyway - counter_method = ('belongs_to_counter_cache_before_destroy_for_' + self.class.name.downcase).to_sym - if o.respond_to?(counter_method) - class << o - self - end.send(:define_method, counter_method, Proc.new {}) - end + o.mark_for_destruction end send(name).delete_all |