diff options
author | Dmitry Polushkin <dmitry.polushkin@gmail.com> | 2011-12-31 03:56:48 +0000 |
---|---|---|
committer | Dmitry Polushkin <dmitry.polushkin@gmail.com> | 2011-12-31 03:56:48 +0000 |
commit | 5d2bf4d12985ba92079178787ea47d4e3992a747 (patch) | |
tree | 210f087118e8dfc58d5a7adab0c41a8475dcd41d /activerecord/lib/active_record/associations | |
parent | 04bc40ff501b1bf81bec7ce3937cb06c896ffc69 (diff) | |
download | rails-5d2bf4d12985ba92079178787ea47d4e3992a747.tar.gz rails-5d2bf4d12985ba92079178787ea47d4e3992a747.tar.bz2 rails-5d2bf4d12985ba92079178787ea47d4e3992a747.zip |
Removed metaclass from the has_many dependency destroy method. Fixes #2954
Diffstat (limited to 'activerecord/lib/active_record/associations')
-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 |