diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 4baa70a..d2d2831 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -86,7 +86,7 @@ public function whereIsRoot() */ public function whereAncestorOf($id, $andSelf = false, $boolean = 'and') { - $keyName = $this->model->getKeyName(); + $keyName = $this->model->getTable() . '.' . $this->model->getKeyName(); if (NestedSet::isNode($id)) { $value = '?'; @@ -100,7 +100,7 @@ public function whereAncestorOf($id, $andSelf = false, $boolean = 'and') ->toBase() ->select("_.".$this->model->getRgtName()) ->from($this->model->getTable().' as _') - ->where($keyName, '=', $id) + ->where($this->model->getKeyName(), '=', $id) ->limit(1); $this->query->mergeBindings($valueQuery); @@ -108,13 +108,13 @@ public function whereAncestorOf($id, $andSelf = false, $boolean = 'and') $value = '('.$valueQuery->toSql().')'; } - $this->query->whereNested(function ($inner) use ($value, $andSelf, $id) { + $this->query->whereNested(function ($inner) use ($value, $andSelf, $id, $keyName) { list($lft, $rgt) = $this->wrappedColumns(); $inner->whereRaw("{$value} between {$lft} and {$rgt}"); if ( ! $andSelf) { - $inner->where($this->model->getKeyName(), '<>', $id); + $inner->where($keyName, '<>', $id); } }, $boolean);