scope_column如何在symfony嵌套集中工作?

时间:2011-07-12 19:14:37

标签: symfony1 nested set propel

我想知道scope_column如何在symfony中使用Propel嵌套集。

我想使用嵌套集从表单中保存每个项目。这里有一些代码:

子菜单模型具有以下属性:  id,parent_id,url,menu_user_atribute_id

//SubMenu.php

public function doSave(PropelPDO $con)
{
  if($this->getParentId() == null)
  {
    $this->makeRoot();
  }else{
    $parent = SubMenuPeer::retrieveByPK($this->getParentId());
    $this->setParent($parent);
    $this->getParent()->addChild($this);
  }
  parent::doSave($con);
}

但是当我想保存另一个带有diferente范围值的项目(在本例中为scope_column = menu_user_role_id)时,它将被第一个scopeValue替换。

the submenu item 19 with menu_user_role=28, but it should be 29.

id  parent_id  menu_user_role_id  Detail_url_id   TreeLeft  treeRight  treeLevel
17  NULL      28                  1               1         2          0
18  17        28                  2               2         3          1
19  17        28                  3               2         3          1

1 个答案:

答案 0 :(得分:2)

您需要先启用范围的使用,然后才能定义scope_id:

<behavior name="nested_set">
  <parameter name="use_scope" value="true" />
  <parameter name="scope_column" value="menu_user_role_id" />
</behavior>