Implement Element.move_to to move an element to another parent
A further optimization after the SQL implementations of add_parent and remove_child (#1294 (closed), #1296 (closed)): an Element.move_to(parent) method, that replaces all parent paths of an element with just one new parent.
hide empty members
hide circle
left to right direction
class W
W --> A
X --> A
Y --> B
Z --> B
A ..> C #line:red;text:red : remove
B ..> C #line:green;text:green : add
C --> D
C.move_to(B)
| Element | Path | Ordering |
|---|---|---|
| W | [] | 0 |
| X | [] | 0 |
| Y | [] | 0 |
| Z | [] | 0 |
| A | W | 0 |
| A | X | 0 |
| B | Y | 0 |
| B | Z | 0 |
| D |
|
0 |
| D |
|
0 |
| C |
|
0 |
| C |
|
0 |
| D |
|
0 |
| D |
|
0 |
| D |
|
0 |
| D |
|
0 |
Unlike with add_parent and remove_child, we will not try to UPDATE any existing paths. Such an update is too complex in many cases, as this requires handling a diff between the paths of all the previous parents and the paths of the new parent, and any possible performance increase here does not justify the added complexity. We will just insert the paths for the new parent, and delete the paths of the other parents.
move_to is an interesting gain over the existing move_element task, which calls remove_child for each parent path then add_parent, in that every previous parent path can be deleted in one query.