我正在寻找一种在一个数据库查询中获取嵌套集的方法。
schema.yml
Category:
actAs:
NestedSet:
hasManyRoots: true
rootColumnName: root_id
columns:
name: string(255)
$categories = Doctrine::getTable('Category')->getTree();
//SELECT * FROM category c ORDER BY c.root_id asc, c.lft asc
foreach ($categories as $cat)
{
$cat->getNode();
//SELECT * FROM category c WHERE ((c.lft > '1' AND c.rgt < '8') AND c.root_id = '1') ORDER BY c.lft asc
}
所以,总的来说,我得到的查询数量与类别一样多,这很糟糕。有什么想法吗?