-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
[BUG] NestedSet behaviour: appendTo() behaves as prependTo(). #513
Comments
Hi there, Is there a chance that this gets addressed? Thanks! |
Hi, I'll try to deal with this in the near future |
Awesome, most appreciated! |
HI, Provide please script to reproduce (including table schema) |
Sure, I can put something together. But aren't you able to reproduce it with your own code and schema? Cuz that's exactly what I was doing. The same applies to #534. Thanks! |
Unfortunately I still haven't found enough time for this. But I'll try to deal at the weekend. |
ok, I'll try to make it easy for you :-) Will post code ASAP. |
Hi @sergeyklay , Looks like this one is not fixed yet. Tested with branch Table: DROP TABLE IF EXISTS `tree`;
CREATE TABLE IF NOT EXISTS `tree` (
`id` int(11) NOT NULL,
`root` int(11) DEFAULT NULL,
`title` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`lft` int(11) DEFAULT NULL,
`rgt` int(11) DEFAULT NULL,
`level` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
ALTER TABLE `tree` ADD PRIMARY KEY (`id`);
ALTER TABLE `tree` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; Model class: class Node extends \Phalcon\Mvc\Model
{
public $title;
public function initialize()
{
$this->setSource('tree');
$this->addBehavior(new Phalcon\Mvc\Model\Behavior\NestedSet([
'leftAttribute' => 'lft',
'rightAttribute' => 'rgt',
'levelAttribute' => 'level',
'hasManyRoots' => true,
'rootAttribute' => 'root',
]));
}
} The code: $db = new \Phalcon\Db\Adapter\Pdo\Mysql([
'host' => '127.0.0.1',
'username' => 'root',
'password' => 'letmein',
'dbname' => 'test',
]);
$db->query('truncate table tree');
$db->query('ALTER TABLE tree AUTO_INCREMENT=1');
$this->di['db'] = $db;
$root = new Node;
$root->title = 'ROOT';
$root->saveNode();
// Add "A" as child of root
$node1=new Node;
$node1->title='A';
$node1->appendTo($root);
// Add "B" as last child of root - should be below A
$node2=new Node;
$node2->title='B';
$node2->appendTo($root);
// Add "C" as first child of root - should be above A
$node3=new Node;
$node3->title='C';
$node3->prependTo($root); Observed result the DB: Observed visual tree structure:
Expected result the DB: Expected result the DB:
I'll look at #552 tomorrow. Thanks! |
I've realized how it should work. $root = new Node;
$root->title = 'ROOT';
$root->saveNode();
// Add "A" as child of root
$node1 = new Node;
$node1->title = 'A';
$node1->appendTo($root);
// Add "B" as last child of root - should be below A
$node2 = new Node;
$node2->title = 'B';
$node2->appendTo($root);
// Add "C" as first child of root - should be above A
$node3 = new Node;
$node3->title = 'C';
$node3->prependTo($root); This code should create such tree: Red numbers - PK I fixed this issue in #552 |
I've tested with #552 and tree looks as expected. |
Fixed in |
Hi,
I think there is a bug in inserting nodes to parent.
All newly inserted nodes are created as parent's first node (or, before any other sibling), regardless of whether appendTo() or prependTo() is used.
Here's how the rows look like as a result of appendTo() or prependTo():
As you can see node ID#16 was inserted last, however its lft value is lower than of its sibling ID#2 which was inserted before.
Thoughts?
Thanks!
The text was updated successfully, but these errors were encountered: