Skip to content

Cannot access root or children of node within before_destroy filter #168

Open
@kinman-enphase

Description

@kinman-enphase

On Ruby 2.2.2 and Rails 4.0.10: Before destroying a node, I want to move its children to the root node of the tree.

before_destroy :move_children

def move_children
  self.children.update_all(parent_id: self.root.id)
end

self.root.id throws an exception because self.root is nil. If I access it from within the corresponding controller, I can reach it, but I prefer to put this logic in the model.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions