Thanks joeles, but that won’t work methinks because in nested sets we’re not tracking the parentid to establish a relationship. The relationship is maintained by the lft and rgt column values. I suppose a column could be added to the table that tracks the parentid when a child is inserted, but that would also require modification of the deletion and (sub) tree moving and deletion methods as entries may become orphaned otherwise.
The goal is to compute the parent from the lft and rgt comparison. In esras model, there is a getAncestor() function - which should actually be called getAncestry() - which returns the path to a given childnode in a tree (not the parent as stated in the docs). I’m trying to get a modification of that to only return the immediate parent.
Building on top of that method, you can get the ancestry (path to a node) by comparing parent.lft < node.lft AND parent.right > node.right.
Now there is a way to compute the depth of nodes in a tree. It’s not in the class, but I’m using the code as shown on the mysql.com article. The solution to my problem will likely be in a combination of the ancestry AND where parent.depth = node.depth -1. That should do the trick.
I’ve just not been able to successfully wrap it into a SQL query.
