How to get some child nodes by id with all parents (DoctrineExtensions, Gedmo-Tree NestedTreeRepository, Symfony)


I have a category entity.
Every category can have subcategories.

Now I want to get specific category nodes by id with all its parents

My current solution (custom repository function):

public function getChildrenHierarchyByCategoryIDs($categoryIDsArray)
    $qb = $this->getNodesHierarchyQueryBuilder();
    $qb->andWhere(' in (:categoryIDs)')
       ->setParameter('categoryIDs', $categoryIDsArray)
        ->orWhere(' in (:rootNodes)') // "Workaround", get all available root nodes (1st level only) manually, because I don't know how to get them by children's parentID (node.parent) "automatically" (with second level etc.)
        ->setParameter('rootNodes', $this->getRootNodes())

    $aComponents = $qb->getQuery()->getResult(DoctrineORMQuery::HYDRATE_ARRAY);

    return $this->buildTreeArray($aComponents);


How can I get the parents (of all nodes found by id) automatically, instead of fetching every possible parent manually by id (See “Workaround” in code)?

I can’t find any solution..

I think it should be something like: ->orWhere(' in (node.parent)') which is not working. ([Syntax Error] line 0, col 89: Error: Expected Literal, got ‘node’)

Thanks in advance for taking your time!

Source: Symfony Questions