Open
Description
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.