【问题标题】:How to recover root nodes如何恢复根节点
【发布时间】:2015-05-23 15:28:25
【问题描述】:

使用 symfony2 和教义树扩展的教义2,我最近更新了一个实体,使其成为教义嵌套集树。

一个原则架构更新强制添加了带有空数据的右列。

然后我运行以下代码:

        $repo = $this->getDoctrine()->getRepository('AppBundle:FoodAnalytics\Recipe');

        $repo->verify();
// can return TRUE if tree is valid, or array of errors found on tree
        $repo->recover();
        $this->flush(); // important: flush recovered nodes
// if tree has errors it will try to fix all tree

它成功恢复了左右和水平值,但没有恢复根。 我不能手动设置根值(被教义监听器禁止)。

如何更新这些根值以便树可以正常工作?

谢谢!

【问题讨论】:

    标签: php symfony doctrine-orm tree nested


    【解决方案1】:

    好吧,我没有找到面向对象的解决方案,所以我选择了原始 SQL 查询。 我在任何实体获得父级之前执行此操作,因此每个实体的根值应等于其自己的 id。

    在phpmyadmin中,粘贴以下sql查询并执行:

    update recipe
    set recipe.root = recipe.id
    

    【讨论】:

      猜你喜欢
      • 2018-10-06
      • 2021-12-15
      • 1970-01-01
      • 1970-01-01
      • 2018-05-22
      • 2016-08-04
      • 1970-01-01
      • 2017-05-17
      • 1970-01-01
      相关资源
      最近更新 更多