-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Closed
Description
Steps to reproduce
- Define the following classes
class Parent
has_one :child, dependent: :destroy
end
class Child
belongs_to :parent, inverse_of: :child
before_destroy { throw :abort }
end
- Instanciate as follows:
c = Child.create
p = Parent.create(child: c)
- Then, destroy the parent
p.destroy
Expected behavior
Neither the parent nor the child should be deleted.
throw :abort
should propagate to the parent who called :destroy on the child.
p.destroyed? # false
p.child.destroyed? # false
Actual behavior
The parent is being destroyed.
p.destroyed? # true
p.child.destroyed? # false
PS: If a foreign key is set (which might not be the case for polymorphic associations), then parent is not deleted because it would violate a foreign key contraint, but rails would try it anyways.
System configuration
Rails version: 5.1.5
Ruby version: 2.5.0
Metadata
Metadata
Assignees
Labels
No labels