Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving "root" or parent nodes - Doctrine NestedSet extension

I'm trying to replicate example from gedmo nested-set extension blog, where there are many parent nodes. There you are able to create as many movable parent nodes as well as children (which is typical for a nested set­Wikipedia).

Reading trough comment section, common advice is removing @Gedmo\TreeRoot annotation/mapping, but if I do that, I'm able to move root nodes, but tree becomes broken particularly left and right id's. If I keep TreeRoot, and try to move root nodes I get "no node siblings" or something along those lines, as expected.

Looking at live example at extension blog you can see that you are able to create category without parent and move it up or down.

My Category entity - relevant parts:

class Category 
{
    /**
     * @Gedmo\TreeLeft
     * @ORM\Column(name="lft", type="integer")
     */
    private $lft;

    /**
     * @Gedmo\TreeLevel
     * @ORM\Column(name="lvl", type="integer")
     */
    private $lvl;

    /**
     * @Gedmo\TreeRight
     * @ORM\Column(name="rgt", type="integer")
     */
    private $rgt;

    /**
     * @Gedmo\TreeRoot
     * @ORM\Column(name="root", type="integer", nullable=true)
     */
    private $root;

    /**
     * @Gedmo\TreeParent
     * @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
     */
    private $parent;

    /**
     * @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
     * @ORM\OrderBy({"lft" = "ASC"})
     * @Exclude
     */
    private $children;
}

Question: How to make multiple root tree (I would like to avoid creating fake category that will be single root, and add everything else as child of that node), and be able to move root nodes up and down?

P.S. I'm on master branch.

like image 267
Marko Jovanović Avatar asked Nov 27 '22 16:11

Marko Jovanović


1 Answers

The tree will break on concurrent updates see tree locking documentation. When tree updates it runs two atomic update queries, which in turn can be run from a concurrent request with a different state not aware about ones being done. When having this covered, a tree should maintain its stability, I have successfully used this extension for 100K - 1M node tree, which was based on roots though.

If you are sure these tree brakes are not related to concurrency, then please open an issue on github with an use case description.

like image 56
Gediminas Avatar answered Dec 06 '22 08:12

Gediminas