Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree breaks when moving #90

Open
dkhlystov opened this issue Feb 11, 2016 · 2 comments
Open

Tree breaks when moving #90

dkhlystov opened this issue Feb 11, 2016 · 2 comments

Comments

@dkhlystov
Copy link

Data before:

CREATE TABLE IF NOT EXISTS `Menu` (
  `id` int(10) NOT NULL,
  `lft` int(11) NOT NULL,
  `rgt` int(11) NOT NULL,
  `depth` int(11) NOT NULL,
  `active` tinyint(1) DEFAULT '1',
  `name` varchar(50) NOT NULL,
  `url` varchar(100) DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
INSERT INTO `Menu` (`id`, `lft`, `rgt`, `depth`, `active`, `name`, `url`) VALUES
(1, 1, 8, 0, 1, 'Root', NULL),
(2, 3, 4, 2, 1, 'Node 1-1', NULL),
(3, 2, 5, 1, 1, 'Node 1', NULL),
(5, 6, 7, 1, 1, 'Node 2', NULL);

Moving code:

$model = Menu::findOne(2);
$target = Menu::findOne(5);
$model->insertAfter($target);
$model->insertBefore($target);

Data after:

id  lft rgt depth   active  name    url
1   1   8   0   1   Root    NULL
3   2   4   1   1   Node 1  NULL
5   4   5   1   1   Node 2  NULL
2   6   7   1   1   Node 1-1    NULL

On 'Node 1' (id:3) there are wrong 'rgt' value

@ebuzzz
Copy link

ebuzzz commented Jun 20, 2016

In my experience, moving is a hard thing to get right with these kind of nested sets. I haven't used this specific implementation, but normally you're better of rebuilding the tree from the first level both nodes (old and new) are children of.

@dkhlystov
Copy link
Author

It is unlikely that the code I wrote is used. But this is extension bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants