【发布时间】:2015-09-17 22:57:42
【问题描述】:
我在我的应用程序中使用了一个学说嵌套集合树。
我可以使用
轻松检索整棵树 $repo->childrenHierarchy(
null, /* starting from root nodes */
false, /* false: load all children, true: only direct */
$options
)
我想要的是根据外键过滤这棵树的实体(类别属于用户,所以每个类别都有一个 userId)
不幸的是,接受回调以过滤节点的选项不允许过滤外键,外键值不包含在节点数组中:
$options = array(
'decorate' => true,
'rootOpen' => '<ul>',
'rootClose' => '</ul>',
'childOpen' => function ($node) use($user) {
// $node does not contain any foreign key
if ($node['userId'] != $user->getId()) {
return null;
}
return "<li id='".$node['id']."'>";
},
'childClose' => '</li>',
);
我该如何解决这个问题?
【问题讨论】:
标签: symfony doctrine-orm tree doctrine nested