|
|
@@ -222,18 +222,19 @@ class TreeBehavior extends Behavior
|
|
|
$left = $entity->get($config['left']);
|
|
|
$right = $entity->get($config['right']);
|
|
|
$diff = $right - $left + 1;
|
|
|
+ $primaryKey = $this->_getPrimaryKey();
|
|
|
|
|
|
if ($diff > 2) {
|
|
|
/* @var \Cake\Database\Expression\QueryExpression $expression */
|
|
|
- $expression = $this->_scope($this->_table->find())
|
|
|
+ $finder = $this->_scope($this->_table->find())
|
|
|
+ ->select([$primaryKey], true)
|
|
|
->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->_table->deleteAll([$primaryKey . ' IN' => $finder]);
|
|
|
}
|
|
|
|
|
|
$this->_sync($diff, '-', "> {$right}");
|