Skip to content

Commit

Permalink
Fixed issue Multi-Tree Deleting Nodes outside the Scope
Browse files Browse the repository at this point in the history
GitHub Issue #11289
  • Loading branch information
jonmc1 committed Oct 9, 2017
1 parent 4fabcc8 commit 66bfde9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/ORM/Behavior/TreeBehavior.php
Expand Up @@ -224,12 +224,16 @@ public function beforeDelete(Event $event, EntityInterface $entity)
$diff = $right - $left + 1;

if ($diff > 2) {
$this->_table->deleteAll(function ($exp) use ($config, $left, $right) {
/* @var \Cake\Database\Expression\QueryExpression $exp */
return $exp
->gte($config['leftField'], $left + 1)
->lte($config['leftField'], $right - 1);
});
/* @var \Cake\Database\Expression\QueryExpression $expression */
$expression = $this->_scope($this->_table->find())
->where(function ($exp) use ($config, $left, $right) {
return $exp
->gte($config['leftField'], $left + 1)
->lte($config['leftField'], $right - 1);
})
->clause('where');

$this->_table->deleteAll($expression);
}

$this->_sync($diff, '-', "> {$right}");
Expand Down

0 comments on commit 66bfde9

Please sign in to comment.