File tree 2 files changed +13
-0
lines changed
2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,9 @@ def really_destroy!(update_destroy_attributes: true)
182
182
association_data = self . send ( name )
183
183
# has_one association can return nil
184
184
# .paranoid? will work for both instances and classes
185
+ if association_data . nil? && reflection . has_one? && reflection . klass . paranoid?
186
+ association_data = reflection . klass . only_deleted . find_by ( reflection . foreign_key => self . id )
187
+ end
185
188
next unless association_data && association_data . paranoid?
186
189
if reflection . collection?
187
190
next association_data . with_deleted . find_each { |record |
Original file line number Diff line number Diff line change @@ -1418,6 +1418,16 @@ def test_update_has_many_through_relation_delete_associations
1418
1418
assert_equal 2 , employer . jobs . with_deleted . count
1419
1419
end
1420
1420
1421
+ def test_really_destroy_against_soft_deleted_object_with_has_one_association
1422
+ model = ParanoidModelWithHasOne . create ( paranoid_model_with_belong : ParanoidModelWithBelong . create )
1423
+ assert_equal 1 , ParanoidModelWithBelong . with_deleted . count
1424
+ model . destroy
1425
+ assert_equal 1 , ParanoidModelWithBelong . with_deleted . count
1426
+ model . reload
1427
+ model . really_destroy!
1428
+ assert_equal 0 , ParanoidModelWithBelong . with_deleted . count # I think this should fail.
1429
+ end
1430
+
1421
1431
private
1422
1432
def get_featureful_model
1423
1433
FeaturefulModel . new ( :name => "not empty" )
You can’t perform that action at this time.
0 commit comments