getChildren
$parent argument specify only from which root element get the tree. You can see code of childrenQueryBuilder
function in NestedTreeRepository
.
To fetch all childs I use own function in repository.
public function getTreeAsFlatArray( AbstractTreeNode $parent = null, array $options = array() ) {
$qb = $this->createQueryBuilder('node');
$qb
->andWhere('node.lft > :parent_lft')
->setParameter('parent_lft', $parent->getLft() )
->andWhere('node.lft < :parent_rgt')
->setParameter('parent_rgt', $parent->getRgt() )
->andWhere('node.level <= :level')
->setParameter('level', $parent->getLevel() + $o['depth'])
->andWhere('node.root = :root')
->setParameter('root', $parent->getRoot())
;
...
}
If you only need direct childs simplets way to specify childs field in entity
/**
* @ORM\OneToMany(targetEntity="AbstractTreeNode", mappedBy="parent", fetch="EXTRA_LAZY")
* @ORM\OrderBy({"lft" = "ASC"})
*/
protected $childs;