Implement removing one of multiple parents of an element using SQL
When calling Element.remove_child
, if the child has more than one parent, then we can use just one DELETE
query to remove the paths of this parent. We can trust that there will still be some paths remaining for all of the children, since they have other parents, so no update is necessary. This is the inverse operation of #1287 (closed).
Example: Z.remove_child(A)
hide empty members
hide circle
left to right direction
class X
X --> A
Y --> A
Z ..> A
A --> B
B --> C
Element | Path | Ordering |
---|---|---|
X | [] | 0 |
Y | [] | 0 |
Z | [] | 0 |
A | X | 0 |
A | Y | 0 |
A |
|
0 |
B | X A | 0 |
B | Y A | 0 |
B |
|
0 |
C | X A B | 0 |
C | Y A B | 0 |
C |
|
0 |
We can implement this as a shortcut: once we have retrieved the current paths of the child, we can tell if the child has multiple parents, and we can switch to this single DELETE
query when possible. If this was the last parent of the child, then we fall back to the current Python implementation.
Edited by Erwan Rouchet