etrepat / baum

Baum is an implementation of the Nested Set pattern for Laravel's Eloquent ORM.
http://etrepat.com/baum
MIT License
2.24k stars 459 forks source link

buildTree() not updating lft & rgt #192

Open azulkipli opened 8 years ago

azulkipli commented 8 years ago

On frontend I use this plugin https://github.com/dbushell/Nestable My method code


        $data = \Request::all();

        $categories = json_decode($data['sort_category'],true);

        Category::rebuild(true);

        Category::buildTree($categories);

        Category::rebuild(true);

        return redirect()->route('admin.categories.sortorder');

So copied from dd($categories) I have structure like this;

array:4 [▼
  0 => array:2 [▼
    "id" => 1
    "children" => array:5 [▶]
  ]
  1 => array:2 [▼
    "id" => 2
    "children" => array:5 [▶]
  ]
  2 => array:2 [▼
    "id" => 3
    "children" => array:1 [▼
      0 => array:2 [▼
        "id" => 15
        "children" => array:1 [▼
          0 => array:1 [▼
            "id" => 16
          ]
        ]
      ]
    ]
  ]
  3 => array:1 [▼
    "id" => 17
  ]
]

Then I tried to move category id: 17 to the top of category id:3

When I dd($categories) the array like this;

array:4 [▼
  0 => array:2 [▼
    "id" => 1
    "children" => array:5 [▶]
  ]
  1 => array:2 [▼
    "id" => 2
    "children" => array:5 [▶]
  ]
 2 => array:1 [▼
    "id" => 17
  ]
  3 => array:2 [▼
    "id" => 3
    "children" => array:1 [▼
      0 => array:2 [▼
        "id" => 15
        "children" => array:1 [▼
          0 => array:1 [▼
            "id" => 16
          ]
        ]
      ]
    ]
  ]

]

I update the Categories with Category:buildTree($myarray), when I see the database the lft & rgt didnt change, even I use Category::rebuild(true)

Is this bug ? Can anyone here help me to fix this?

Thanks

mikehins commented 8 years ago

Same here. Have you found a solution ?

gazsp commented 8 years ago

I've forked this repo and am looking to continue it's development. If you'd like me to look in to this, please create a failing unit test and submit a pull request here: https://github.com/gazsp/baum