How to update left, right, level values on existin

2019-05-21 19:41发布

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条回答
Emotional °昔
2楼-- · 2019-05-21 19:51

To update left and right just:

    $repo->verify();
    $repo->recover();
    $em->flush();

But I'm still looking how to update levels :)

查看更多
登录 后发表回答