Skip to content

throw :abort does not propagate to parent class #32022

@gorodscy

Description

@gorodscy

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions