4 ms·
That will prevent a child being its own parent. It won't work for more than one level i.e a post being its own grandchild. Assume (post_id, parent_id) sequence:
by irahul 14y ago
That will prevent a child being its own parent. It won't work for more than one level i.e a post being its own grandchild. Assume (post_id, parent_id) sequence: (1, 3) -> (2, 1) -> (3, 2).
- zzzeek 14y agoyou can assert that "post_id > parent_id", assuming comments are always created subsequent to the creation of their parents (as is the case here) and that integer identifiers are always increasing (otherwise use timestamps). (1, 3) above would indicate an invalid case (not necessarily a cycle, but a precondition for one).
- swah 14y agoPlease note that the "Closure Table solution involves storing all paths through the tree, not just those with a direct parent-child relationship."
- irahul 14y agoMy bad. I was speed reading, and didn't read the "Closure Table" part.