Permalink
Browse files

Removed metaclass from the has_many dependency destroy method. Fixes #…

  • Loading branch information...
1 parent 04bc40f commit 5d2bf4d12985ba92079178787ea47d4e3992a747 @dmitry dmitry committed Dec 31, 2011
@@ -33,8 +33,10 @@ def add_counter_cache_callbacks(reflection)
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)
@@ -31,12 +31,7 @@ def define_destroy_dependency_method
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

0 comments on commit 5d2bf4d

Please sign in to comment.