Skip to content
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

Fixes issue #513 #514

Open
wants to merge 2 commits into
base: v5
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 6 additions & 7 deletions src/NodeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ public static function bootNodeTrait()

static::deleting(function ($model) {
// We will need fresh data to delete node safely
// We must delete the descendants BEFORE we delete the actual
// album to avoid failing FOREIGN key constraints.
$model->refreshNode();
});

static::deleted(function ($model) {
$model->deleteDescendants();
});

Expand Down Expand Up @@ -249,7 +248,7 @@ public function children()
*/
public function descendants()
{
return new DescendantsRelation($this->newQuery(), $this);
return new DescendantsRelation($this->newQueryWithoutScopes(), $this);
}

/**
Expand Down Expand Up @@ -338,7 +337,7 @@ public function prevNodes()
*/
public function ancestors()
{
return new AncestorsRelation($this->newQuery(), $this);
return new AncestorsRelation($this->newQueryWithoutScopes(), $this);
}

/**
Expand Down Expand Up @@ -675,7 +674,7 @@ public function newNestedSetQuery($table = null)
{
$builder = $this->usesSoftDelete()
? $this->withTrashed()
: $this->newQuery();
: $this->newQueryWithoutScopes();

return $this->applyNestedSetScope($builder, $table);
}
Expand All @@ -687,7 +686,7 @@ public function newNestedSetQuery($table = null)
*/
public function newScopedQuery($table = null)
{
return $this->applyNestedSetScope($this->newQuery(), $table);
return $this->applyNestedSetScope($this->newQueryWithoutScopes(), $table);
}

/**
Expand Down
17 changes: 10 additions & 7 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ class QueryBuilder extends Builder
*/
public function getNodeData($id, $required = false)
{
$query = $this->toBase();
$lftName = $this->model->getLftName();
$rgtName = $this->model->getRgtName();

$query->where($this->model->getKeyName(), '=', $id);

$data = $query->first([ $this->model->getLftName(),
$this->model->getRgtName() ]);
$data = $this->toBase()
->where($this->model->getKeyName(), '=', $id)
->first([$lftName, $rgtName]);

if ( ! $data && $required) {
throw new ModelNotFoundException;
}

return (array)$data;
// Ensure that the result only contains the required attributes in
// correct order and nothing else.
// The query above might accidentally return more attributes, if
// a global scope is defined for the query by the base model.
return $data ? [$lftName => $data[$lftName], $rgtName => $data[$rgtName]] : [];
}

/**
Expand Down