问题
http://sqlfiddle.com/#!9/1d4a6/1
I have existing hierarchical data for categories. I have been using traditional approach to get parent, child etc using parent_id.
Now I am trying to use Gedmo doctrine extension for the same. I have installed the extension and updated schema.
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();
But above columns for my old categories have 0 values.
I tried fetching all results and updating them but it still all values for above columns are 0.
Update 1:
Adding this
$repo->recover();
populated lft and rgt but still lvl and root are 0 & NULL resp.
回答1:
To update left and right just:
$repo->verify();
$repo->recover();
$em->flush();
But I'm still looking how to update levels :)
来源:https://stackoverflow.com/questions/29533361/how-to-update-left-right-level-values-on-existing-category-hierarchy-data-usin