protected function _processDelete($entity, $options)
{
if ($entity->isNew()) {
return false;
}
$primaryKey = (array) $this->primaryKey();
if (!$entity->has($primaryKey)) {
$msg = 'Deleting requires all primary key values.';
throw new InvalidArgumentException($msg);
}
if ($options['checkRules'] && !$this->checkRules($entity, RulesChecker::DELETE, $options)) {
return false;
}
$event = $this->dispatchEvent('Model.beforeDelete', ['entity' => $entity, 'options' => $options]);
if ($event->isStopped()) {
return $event->result;
}
$this->_associations->cascadeDelete($entity, ['_primary' => false] + $options->getArrayCopy());
$query = $this->query();
$conditions = (array) $entity->extract($primaryKey);
$statement = $query->delete()->where($conditions)->execute();
$success = $statement->rowCount() > 0;
if (!$success) {
return $success;
}
$this->dispatchEvent('Model.afterDelete', ['entity' => $entity, 'options' => $options]);
return $success;
}