我有以下代码:
$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;
}
}
这很好,但是getparent()调用会为每个节点执行查询。是否可以通过运行数百个额外查询来检索父ID。