Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dd9434d

Browse files
author
Killian Thomas
committedSep 25, 2018
Fix "ambiguous column" issue when using whereAncestorOr or whereDescendantOf with additional join(s)
If joins are made between the table using the NodeTrait and the table itself, using conditions whereDescendantOf or whereAncestorOf would throw an Integrity Constraint Violation error on columns _lft and/or _rgt.
1 parent 8f2882b commit dd9434d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed
 

‎src/QueryBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ public function whereAncestorOf($id, $andSelf = false, $boolean = 'and')
110110

111111
$this->query->whereNested(function ($inner) use ($value, $andSelf, $id, $keyName) {
112112
list($lft, $rgt) = $this->wrappedColumns();
113+
$wrappedTable = $this->query->getGrammar()->wrapTable($this->model->getTable());
113114

114-
$inner->whereRaw("{$value} between {$lft} and {$rgt}");
115+
$inner->whereRaw("{$value} between {$wrappedTable}.{$lft} and {$wrappedTable}.{$rgt}");
115116

116117
if ( ! $andSelf) {
117118
$inner->where($keyName, '<>', $id);
@@ -182,7 +183,7 @@ public function ancestorsAndSelf($id, array $columns = [ '*' ])
182183
*/
183184
public function whereNodeBetween($values, $boolean = 'and', $not = false)
184185
{
185-
$this->query->whereBetween($this->model->getLftName(), $values, $boolean, $not);
186+
$this->query->whereBetween($this->model->getTable() . '.' . $this->model->getLftName(), $values, $boolean, $not);
186187

187188
return $this;
188189
}

0 commit comments

Comments
 (0)
Please sign in to comment.