fremail / sequelize-nested-set

Library to store and manage nested set trees using Sequelize
MIT License
39 stars 10 forks source link

Error while moving node between trees #18

Closed ilgiz-badamshin closed 3 years ago

ilgiz-badamshin commented 3 years ago

From documentation:

  1. Moving a record Warning! You can move record only if it's a valid node == it has its own place in the tree == it has left and right values. If it doesn't, please see Creating a record page.
  2. Creating a record Warning! You can use these functions only with records w/o its own place in the tree (w/o left and right values in other words). If you need to move the existing records, see Moving a record page.

For example method: moveAsFirstChildOf. If source node and dest node has different rootId, then called moveBetweenTrees, that call insertAsFirstChildOf, that throw exception: "Cannot insert the node that has its place in the tree", becouse node exists and we can't use methotds insertXXX.

So no one moveXXX from different trees is not working. Maybe need to call detach(), before insertXXX methods? Or i some where have mistake?

fremail commented 3 years ago

@ilgiz-badamshin you are right. It's a bug. Thank you for reporting.

If you have ideas how to fix it, PR is welcome!

ilgiz-badamshin commented 3 years ago

19 - fix moveBetweenTrees

20 - fix bug with siblings

fremail commented 3 years ago

@ilgiz-badamshin thank you for your PRs! I merged them and created a new release with the changes - see v 1.5.1