lazychaser / laravel-nestedset

Effective tree structures in Laravel 4-8
3.66k stars 472 forks source link

If you delete the middle of the tree, the descendants of that tree will be deleted. How can I link the descendants to the target parent without deleting the descendants? #418

Open snk-lab opened 5 years ago

snk-lab commented 5 years ago

If you delete the middle of the tree, the descendants of that tree will be deleted. How can I link the descendants to the target parent without deleting the descendants? If the target element is deleted after changing to Array, and then rebuildTree is executed, parent_id disappears and the Tree structure is broken. Is there any good way?

I'm not good at English. I'm sorry

snk-lab commented 5 years ago

It seems to be able to do this way for now.

$parent = $self->parent()->first(); $children = $parent->defaultOrder()->descendantsOf($self->id); Model::rebuildSubtree($parent, $children->toTree()->toArray()); $self->delete();

Since the sibling is also deleted when the third argument of rebuildSubtree is set to true, it was deleted separately. I hope there is a better and better way.

sreerajlal commented 4 years ago

is there any better solution to solve this ...