Skip to content

Fixes the join problem #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link

@oujesky oujesky May 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem here, as $keyName is also used below on line 103 in subquery and this needs to be in form of really just the key column name. If the table name is specified here, it won't work as the table is referenced by alias _ in the subquery.

$keyName should stay as is and the table name should be added only on line 117, where it is the only place where it is actually needed and prevents Column '...' in where clause is ambiguous . errors.

That is also possibly the cause why the build if failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


if (NestedSet::isNode($id)) {
$value = '?';
Expand All @@ -100,21 +100,21 @@ 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);

$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);

Expand Down