Commit e7d075f1 by Ryan Bigg

Really only destroy associated records

parent c9227381
......@@ -135,7 +135,10 @@ class ActiveRecord::Base
end
if dependent_reflections.any?
dependent_reflections.each do |name, _|
self.send(name).unscoped.each(&:really_destroy!)
associated_records = self.send(name)
# Paranoid models will have this method, non-paranoid models will not
associated_records = associated_records.with_deleted if associated_records.respond_to?(:with_deleted)
associated_records.each(&:really_destroy!)
end
end
destroy!
......
......@@ -309,6 +309,17 @@ class ParanoiaTest < test_framework
refute RelatedModel.unscoped.exists?(child.id)
end
def test_real_destroy_dependent_destroy_after_normal_destroy_does_not_delete_other_children
parent_1 = ParentModel.create
child_1 = parent_1.very_related_models.create
parent_2 = ParentModel.create
child_2 = parent_2.very_related_models.create
parent_1.destroy
parent_1.really_destroy!
assert RelatedModel.unscoped.exists?(child_2.id)
end
if ActiveRecord::VERSION::STRING < "4.1"
def test_real_destroy
model = ParanoidModel.new
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment