Skip to content

Commit cf299b0

Browse files
committed
fix: enhance root node insertion logic to check for existing nodes with left attribute.
1 parent 6321cb8 commit cf299b0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/NestedSetsBehavior.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,10 @@ protected function beforeInsertNode(int $value, int $depth): void
10701070
*/
10711071
protected function beforeInsertRootNode(): void
10721072
{
1073-
if ($this->treeAttribute === false && $this->getOwner()::find()->roots()->exists()) {
1073+
if (
1074+
$this->treeAttribute === false &&
1075+
$this->getOwner()::find()->andWhere([$this->leftAttribute => 1])->exists()
1076+
) {
10741077
throw new Exception('Can not create more than one root when "treeAttribute" is false.');
10751078
}
10761079

0 commit comments

Comments
 (0)