How to get Parent id of node in doctrine nested set
Asked Answered
S

0

6

I have the following code :

$treeObject = Doctrine_Core::getTable('Category')->getTree();
$rootColumnName = $treeObject->getAttribute('rootColumnName');

foreach ($treeObject->fetchRoots() as $root) {
  $options = array( 'root_id' => $root->$rootColumnName  );

  foreach($treeObject->fetchTree($options) as $node) {
    $parent_id = $node->getNode()->getParent()->getId();
    echo $parent_id;
  }
}

This works fine however the getparent() call executes a query for every node. is there away to retrieve the parent id with out running hundreds of extra queries.

Slusher answered 26/2, 2011 at 8:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.