在 CakePHP 树中查找子树
在 CakePHP 中,如何仅选择模型中的 actsAs
树的子树?
我尝试了这个,找到以 label = "My Label"
的项目为首的树
$this->find("threaded", array(
"conditions" => array(
"label" => "My Label"
)
));
...但是查看日志,它运行以下 SQL:
SELECT Menu.id, Menu.parent_id, Menu.lft, Menu.rght, Menu.label, Menu.link
FROM menus Menu
WHERE label = 'My Label'
显然,它只选择一个节点,而不是它的所有孩子。
In CakePHP, how do you select just a subtree in a model which actsAs
tree?
I tried this, to find the tree headed by the item with label = "My Label"
$this->find("threaded", array(
"conditions" => array(
"label" => "My Label"
)
));
...however looking at the logs, it runs this SQL:
SELECT Menu.id, Menu.parent_id, Menu.lft, Menu.rght, Menu.label, Menu.link
FROM menus Menu
WHERE label = 'My Label'
Which obviously only selects the one node, and not all its children.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来你必须像这样分两步完成(来自手册):
不能使用
'label' =>;
条件,因为它只会查找与该条件(父级和子级)匹配的结果。线程
调用中的“my label”'threaded'
仅根据parent_id
重新排列正常查找操作的结果,因此您必须使用lft
/rght
列。It seems you will have to do it in two steps like this (from the manual):
You can't use the
'label' => 'my label'
condition in thethreaded
call, since it would only find results that match that condition, parents and children.'threaded'
only rearranges the results of a normal find operation based on theparent_id
, so you'll have to supply your own condition of what "children" are by using thelft
/rght
columns.