A
A
alestro2015-12-20 21:17:24
PHP
alestro, 2015-12-20 21:17:24

Nested sets how to remove a node and all children?

I found a similar request, but it only removes the node itself, and all child elements remain in their places.
How can a node and all children be removed?

DELETE FROM my_tree WHERE left_key >= $left_key AND right_ key <= $right_key;
UPDATE my_tree SET left_key = IF(left_key > $left_key, left_key – ($right_key - $left_key + 1), left_key), right_key = right_key – ($right_key - $left_key + 1) WHERE right_key > $right_key

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2015-12-20
@Rsa97

The request seems to be correct. Most likely the problem is in the wrong organization of the nested set in the database. In a correct nested set condition
describes a node with all its children.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question