如何恢复根节点

Séb*_*ien 5 php tree nested symfony doctrine-orm

使用带有doctrine树扩展的symfony2和doctrine2,我最近更新了一个实体,使其成为一个学说嵌套集树.

doctrine架构更新强制使用空数据添加了正确的列.

然后我运行了以下代码:

        $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
Run Code Online (Sandbox Code Playgroud)

它成功恢复了左右和水平值但不是root.我无法手动设置根值(由doctrine listener禁止).

如何更新这些根值以使树能够正常工作?

谢谢 !

Séb*_*ien -1

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

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

update recipe
set recipe.root = recipe.id
Run Code Online (Sandbox Code Playgroud)