Skip to content

Commit

Permalink
Alias fields to avoid ambiguity.
Browse files Browse the repository at this point in the history
Closes #6794
  • Loading branch information
ADmad committed Jun 12, 2015
1 parent 2062361 commit 8397027
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/ORM/Behavior/TreeBehavior.php
Expand Up @@ -772,19 +772,20 @@ protected function _recoverTree($counter = 0, $parentId = null, $level = -1)
{
$config = $this->config();
list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']];
$pk = (array)$this->_table->primaryKey();
$primaryKey = $this->_getPrimaryKey();
$aliasedPrimaryKey = $this->_table->aliasField($primaryKey);

$query = $this->_scope($this->_table->query())
->select($pk)
->where([$parent . ' IS' => $parentId])
->order($pk)
->select([$aliasedPrimaryKey])
->where([$this->_table->aliasField($parent) . ' IS' => $parentId])
->order([$aliasedPrimaryKey])
->hydrate(false);

$leftCounter = $counter;
$nextLevel = $level + 1;
foreach ($query as $row) {
$counter++;
$counter = $this->_recoverTree($counter, $row[$pk[0]], $nextLevel);
$counter = $this->_recoverTree($counter, $row[$primaryKey], $nextLevel);
}

if ($parentId === null) {
Expand All @@ -798,7 +799,7 @@ protected function _recoverTree($counter = 0, $parentId = null, $level = -1)

$this->_table->updateAll(
$fields,
[$pk[0] => $parentId]
[$primaryKey => $parentId]
);

return $counter + 1;
Expand Down

0 comments on commit 8397027

Please sign in to comment.