Nested Set - Depth of a Sub-Tree - Active Record |
[eluser]Otemu[/eluser]
Hi, After reading the excellent managing hierarchical data in mysql I was wondering if anyone knows how to write the query below in active record or if it even possible with AR: Code: SELECT node.name, (COUNT(parent.name) - (sub_tree.depth + 1)) AS depth Since all my queries currently in AR be nice to continue that trend, however if not then I guess I have to run this one as standard mysql. Any help be appreciated.
[eluser]PhilTem[/eluser]
It's not possible with CI's standard AR-class since you got a subquery. There are however some techniques that allow subqueries, like you can find here or here (just to name a few). I personally never looked into this subqueries thingy because I didn't need it so far. Or if I needed it most of the times I was able to just run two separate queries and combine the results according to my needs. But since I'm working with Nested Sets at the moment what seems to be much more difficult than standard table layouts, I guess there's no way to avoid subqueries
|
Welcome Guest, Not a member yet? Register Sign In |