Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/NestedSetsBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,13 @@ public function appendTo(ActiveRecord $node, bool $runValidation = true, array|n
$this->operation = self::OPERATION_APPEND_TO;
$this->node = $node;

return $this->getOwner()->save($runValidation, $attributes);
$result = $this->getOwner()->save($runValidation, $attributes);

if ($result === true) {
$node->refresh();
}

return $result;
}

/**
Expand Down
46 changes: 46 additions & 0 deletions tests/NestedSetsBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,52 @@ public function testAppendChildNodeToRootCreatesValidTreeStructure(): void
}
}

public function testReturnShiftedLeftRightAttributesWhenChildAppendedToRoot(): void
{
$this->createDatabase();

$root = new Tree(['name' => 'Root']);

$root->makeRoot();
$root->refresh();

$child = new Tree(['name' => 'Child']);

$child->appendTo($root);
$child->refresh();

self::assertEquals(
1,
$root->lft,
'Root node left value should be \'1\' after \'makeRoot\' and appending a child.',
);
self::assertEquals(
4,
$root->rgt,
'Root node right value should be \'4\' after \'makeRoot\' and appending a child.',
);
self::assertEquals(
2,
$child->lft,
'Child node left value should be \'2\' after being appended to the root node.',
);
self::assertEquals(
3,
$child->rgt,
'Child node right value should be \'3\' after being appended to the root node.',
);
self::assertNotEquals(
0,
$child->lft,
'Child node left value should not be \'0\' after \'appendTo\' operation.',
);
self::assertNotEquals(
1,
$child->rgt,
'Child node right value should not be \'1\' after \'appendTo\' operation.',
);
}

public function testThrowExceptionWhenAppendToParentWithNullRightValue(): void
{
$this->createDatabase();
Expand Down