如何使用symfony中的gedmo树原则扩展来更新现有类别层次结构数据的左,右,级别值? [英] How to update left, right, level values on existing category hierarchy data using gedmo tree doctrine extension in symfony?
问题描述
http://sqlfiddle.com/#!9/1d4a6/1
我有现有的类别分层数据。我一直在使用传统的方法来使用parent_id来获取父,子等。
I have existing hierarchical data for categories. I have been using traditional approach to get parent, child etc using parent_id.
现在我试图使用Gedmo的教义扩展一样。我已经安装了扩展和更新的模式。
Now I am trying to use Gedmo doctrine extension for the same. I have installed the extension and updated schema.
如果我在文档示例中给出了父类孩子的新类别,它可以工作。它正确填充lft,lvl,rgt,根列。
If I create new categories with parent child as given in documentation example, it works. It populates lft, lvl, rgt, root columns properly.
$food = new Entity\Category();
$food->setTitle('Food');
$fruits = new Entity\Category();
$fruits->setParent($food);
$fruits->setTitle('Fruits');
$apple = new Entity\Category();
$apple->setParent($fruits);
$apple->setTitle('Apple');
$milk = new Entity\Category();
$milk->setParent($food);
$milk->setTitle('Milk');
$em->persist($food);
$em->persist($milk);
$em->persist($fruits);
$em->persist($apple);
$em->flush();
但是,对于我旧类别的上面的列,有0个值。
But above columns for my old categories have 0 values.
我尝试获取所有结果并更新它们,但上述列的所有值仍为0.
I tried fetching all results and updating them but it still all values for above columns are 0.
更新1:
添加此
$repo->recover();
填充的lft和rgt,但仍然lvl和root是0&
populated lft and rgt but still lvl and root are 0 & NULL resp.
推荐答案
要更新左右只是:
$repo->verify();
$repo->recover();
$em->flush();
但我还在寻找如何更新级别:)
But I'm still looking how to update levels :)
这篇关于如何使用symfony中的gedmo树原则扩展来更新现有类别层次结构数据的左,右,级别值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!