Quote from: avibodha at Aug 24, 2006, 06:13 PM
Is there any easier way?
Yes, well, maybe not easier, but better I think. Anyway, there is a map available as $modx->documentMap, which is an array of parent document id values keyed for every document in the system. The $modx->getChildIds() function uses this map to build a flat list of all children without any queries to the database, but you could just as easily use the map to create your tree structure ahead of time, then you can issue a single query (rather than looping through and issuing multiple queries, one for each node) as I suggested earlier, to populate a multi-dimensional array of the results.
In SVN, and the upcoming release, getChildIds() can be called with a second depth parameter that can be used to retrieve a node at a time, if you find it that approach more to your liking.
The key point I’m trying to make here is there is no need to query in order to find the children; you can use the $modx->documentMap, $modx->getChildIds() and/or $modx->getParentIds() to define your queries and result set structures any way you want to. I’ll make some more information on this available in the documentation of the API soon; including some sample code.