Skip to content

Commit 91601c3

Browse files
authored
Merge pull request #315 from kelyak/kelyak-patch-1
Fix "ambiguous column" issue when using ancestor/descendant condition
2 parents 8f2882b + dd9434d commit 91601c3

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)