mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Apply patch from 'Carlos Gant'
Remove un-necessary loop when deleting without cascade. Fixes #2050
This commit is contained in:
parent
05df15cdd3
commit
15753ab641
1 changed files with 19 additions and 17 deletions
|
@ -2244,26 +2244,28 @@ class Model extends Object {
|
|||
$savedAssociatons = $this->__backAssociation;
|
||||
$this->__backAssociation = array();
|
||||
}
|
||||
foreach (array_merge($this->hasMany, $this->hasOne) as $assoc => $data) {
|
||||
if ($data['dependent'] === true && $cascade === true) {
|
||||
if ($cascade === true) {
|
||||
foreach (array_merge($this->hasMany, $this->hasOne) as $assoc => $data) {
|
||||
if ($data['dependent'] === true) {
|
||||
|
||||
$model = $this->{$assoc};
|
||||
$conditions = array($model->escapeField($data['foreignKey']) => $id);
|
||||
if ($data['conditions']) {
|
||||
$conditions = array_merge((array)$data['conditions'], $conditions);
|
||||
}
|
||||
$model->recursive = -1;
|
||||
$model = $this->{$assoc};
|
||||
$conditions = array($model->escapeField($data['foreignKey']) => $id);
|
||||
if ($data['conditions']) {
|
||||
$conditions = array_merge((array)$data['conditions'], $conditions);
|
||||
}
|
||||
$model->recursive = -1;
|
||||
|
||||
if (isset($data['exclusive']) && $data['exclusive']) {
|
||||
$model->deleteAll($conditions);
|
||||
} else {
|
||||
$records = $model->find('all', array(
|
||||
'conditions' => $conditions, 'fields' => $model->primaryKey
|
||||
));
|
||||
if (isset($data['exclusive']) && $data['exclusive']) {
|
||||
$model->deleteAll($conditions);
|
||||
} else {
|
||||
$records = $model->find('all', array(
|
||||
'conditions' => $conditions, 'fields' => $model->primaryKey
|
||||
));
|
||||
|
||||
if (!empty($records)) {
|
||||
foreach ($records as $record) {
|
||||
$model->delete($record[$model->alias][$model->primaryKey]);
|
||||
if (!empty($records)) {
|
||||
foreach ($records as $record) {
|
||||
$model->delete($record[$model->alias][$model->primaryKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue