我定义了一个自引用的实体:类别 as shown in the docs。
它基本上创建了一个不可排序的树。
我应该执行什么样的DQL查询,它将选择所有父母,父母的父母......?
编辑:我目前选择所有类别,离开加入他们的父母。然后我使用实体方法提取所有祖先而无需其他查询:
public function hereToRoot( $allCategories )
{
$ancestors = array();
$leftJoinedParent = $this->getParent();
//add parents
while ( !is_null($leftJoinedParent) ) {
$nextAncestor = $allRoles[$leftJoinedParent->getId()];
$ancestors[] = $nextAncestor;
$leftJoinedParent = $nextAncestor->getParent();
}
return array_reverse($ancestors);
}