Commit acd39d7b by astronz

really_destroy! and has_one associations

parent d0e603e9
...@@ -154,10 +154,14 @@ class ActiveRecord::Base ...@@ -154,10 +154,14 @@ class ActiveRecord::Base
if dependent_reflections.any? if dependent_reflections.any?
dependent_reflections.each do |name, _| dependent_reflections.each do |name, _|
associated_records = self.send(name) associated_records = self.send(name)
# Paranoid models will have this method, non-paranoid models will not # has_one association can return nil
associated_records = associated_records.with_deleted if associated_records.respond_to?(:with_deleted) if associated_records && associated_records.respond_to?(:with_deleted)
associated_records.each(&:really_destroy!) # Paranoid models will have this method, non-paranoid models will not
self.send(name).reload associated_records.with_deleted.each(&:really_destroy!)
self.send(name).reload
elsif associated_records && !associated_records.respond_to?(:each) # single record
associated_records.really_destroy!
end
end end
end end
touch_paranoia_column if ActiveRecord::VERSION::STRING >= "4.1" touch_paranoia_column if ActiveRecord::VERSION::STRING >= "4.1"
......
...@@ -435,6 +435,21 @@ class ParanoiaTest < test_framework ...@@ -435,6 +435,21 @@ class ParanoiaTest < test_framework
assert hasOne.reload.deleted_at.nil? assert hasOne.reload.deleted_at.nil?
end end
# covers #131
def test_has_one_really_destroy_with_nil
model = ParanoidModelWithHasOne.create
model.really_destroy!
refute ParanoidModelWithBelong.unscoped.exists?(model.id)
end
def test_has_one_really_destroy_with_record
model = ParanoidModelWithHasOne.create { |record| record.build_paranoid_model_with_belong }
model.really_destroy!
refute ParanoidModelWithBelong.unscoped.exists?(model.id)
end
def test_observers_notified def test_observers_notified
a = ParanoidModelWithObservers.create a = ParanoidModelWithObservers.create
......
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