Moving root nodes Doctrine Tree Nested Extention

Hi, I’ve stumbled upon the same issue as found by some other developers in the past and the solution which was found common was to create a fake root node. The first link is from the exertion issues. The issue suggests it is solved but I can’t work on it. The data entry is as follows.

<?php
        $fruits = new Category();
        $fruits->setTitle('Fruits');
        $fruits->setParent($food);
        
        $vegetables = new Category();
        $vegetables->setTitle('Vegetables');
        $vegetables->setParent($food);
        
        $carrots = new Category();
        $carrots->setTitle('Carrots');
        $carrots->setParent($vegetables);
        
        $homeappliences = new Category();
        $homeappliences->setTitle('Home Appliences');

         $microwave = new Category();
         $microwave->setTitle('Microwave oven');
         $microwave->setParent($homeappliences);

        $this->entityManager->persist($food);
        $this->entityManager->persist($fruits);
        $this->entityManager->persist($vegetables);
        $this->entityManager->persist($carrots);
        $this->entityManager->persist($homeappliences);
        $this->entityManager->persist($microwave);
        $this->entityManager->flush();

        $repo = $this->entityManager->getRepository(Category::class);
        $repo->reorder();
        // Below line throws error: Invalid sort options specified: field - tree_root, direction - ASC
        // Un-comment to see the error.
//        $repo->reorder(null, 'tree_root');

Thanks!

Hi, I’ve understood the fake category creating suggestions and proceeding with the proposed suggestion in my case. It is below to elaborate on how I saw it and proceed with the suggestion.

In the documentation food is an assumed fake category but it is not mentioned by the developers I’ve taken it as a fake or generalized name to organize the category. So, I’ve put food and home appliances under the Supermarket category as I wanted to show food and home appliances. Furthermore, it also solved my issue regarding the creation of multiple menus. For example, a site has multiple menus, so each can be named and worked with. A top menu, a right menu, a left menu so on and so forth. To elaborate this visually is something like below.

--Super makert
    --Food
      --Vegetables
          --Onions
          --Carrots
          --Cabbages
          --Potatoes
      --Fruits
    --Home Appliances
      --Microwave Oven
      ----etc


--Top Menu
    --Home
    --Products
      --Softwares
          --Games
          --IDE
          --Drivers
    --Hardware
      --Motherboards
      ----etc

--Left Menu
    --My account
      --My Services
          --Service 1
          --Service 2
      --Profile
    --Subscriptions
      ----etc

Thanks!