How to update left, right, level values on existing category hierarchy data using gedmo tree doctrine extension in symfony?

寵の児 提交于 2019-12-22 18:05:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!