Removed metaclass from the has_many dependency destroy method. Fixes #2954
This commit is contained in:
parent
04bc40ff50
commit
5d2bf4d129
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user