-
Notifications
You must be signed in to change notification settings - Fork 475
Closed
Description
When a restore is called on a deleted root node, restoreDescendants
is called to restore the children as well. The method looks like this:
$this->descendants()
->where($this->getDeletedAtColumn(), '>=', $deletedAt)
->applyScopes()
->restore();
The applyScopes
method is called, which adds the soft-delete global scope, causing the query to look like this:
update `tree`
set `deleted_at` = '', `updated_at` = '2016-04-14 10:54:08'
where `_lft` between '2' and '10'
and `deleted_at` >= '2016-04-14 10:54:00'
and `tree`.`deleted_at` is null
The two deleted_at conditions are in conflict, which causes the descendants not to restore. The solution would be to add the withTrashed
method, avoiding the soft-delete global scope:
$this->descendants()
->where($this->getDeletedAtColumn(), '>=', $deletedAt)
->withTrashed()
->applyScopes()
->restore();
stefanius
Metadata
Metadata
Assignees
Labels
No labels