目标:
我有一个类别实体。每个类别都可以有子类别。
现在我想通过 id 和它的所有父母来获取特定的类别节点
我当前的解决方案(自定义存储库功能):
public function getChildrenHierarchyByCategoryIDs($categoryIDsArray)
{
$qb = $this->getNodesHierarchyQueryBuilder();
$qb->andWhere('node.id in (:categoryIDs)')
->setParameter('categoryIDs', $categoryIDsArray)
->orWhere('node.id 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(\Doctrine\ORM\Query::HYDRATE_ARRAY);
return $this->buildTreeArray($aComponents);
}
问题:
如何自动获取父节点(由 id 找到的所有节点),而不是通过 id 手动获取每个可能的父节点(参见代码中的“解决方法”)?
我找不到任何解决方案..
我认为它应该是这样的:->orWhere('node.id in (node.parent)')
这是行不通的。([语法错误] 第 0 行,第 89 列:错误:预期文字,得到“节点”)
提前感谢您抽出宝贵时间!