Skip to content

Commit

Permalink
Fix populateTree() wrong secondary using of variable $depth.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulzi committed Oct 13, 2016
1 parent 5a2aa28 commit c4910f5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 37 deletions.
7 changes: 3 additions & 4 deletions NestedIntervalsBehavior.php
Expand Up @@ -277,8 +277,9 @@ public function populateTree($depth = null)
$nodes = $this->getDescendants($depth)->all();
}

$relates = [];
$parents = [$this->owner->getAttribute($this->leftAttribute)];
$key = $this->owner->getAttribute($this->leftAttribute);
$relates[$key] = [];
$parents = [$key];
$prev = $this->owner->getAttribute($this->depthAttribute);
foreach($nodes as $node)
{
Expand All @@ -302,8 +303,6 @@ public function populateTree($depth = null)
$key = $node->getAttribute($this->leftAttribute);
if (isset($relates[$key])) {
$node->populateRelation('children', $relates[$key]);
} elseif ($depth === null) {
$node->populateRelation('children', []);
}
}

Expand Down
67 changes: 34 additions & 33 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/NestedIntervalsBehavior64TestCase.php
Expand Up @@ -119,6 +119,10 @@ public function testPopulateTree()
$node = MultipleTreeNode64::findOne(19);
$node->populateTree();
$this->assertEquals(true, $node->isRelationPopulated('children'));

$node = MultipleTreeNode64::findOne(19);
$node->populateTree(1);
$this->assertEquals(true, $node->isRelationPopulated('children'));
}

public function testIsRoot()
Expand Down
4 changes: 4 additions & 0 deletions tests/NestedIntervalsBehaviorTestCase.php
Expand Up @@ -132,6 +132,10 @@ public function testPopulateTree()
$node = Node::findOne(19);
$node->populateTree();
$this->assertEquals(true, $node->isRelationPopulated('children'));

$node = Node::findOne(19);
$node->populateTree(1);
$this->assertEquals(true, $node->isRelationPopulated('children'));
}

public function testIsRoot()
Expand Down

0 comments on commit c4910f5

Please sign in to comment.