diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 35dc9bdc6b4..3442a54bbc6 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2244,26 +2244,28 @@ protected function _deleteDependent($id, $cascade) { $savedAssociatons = $this->__backAssociation; $this->__backAssociation = array(); } - foreach (array_merge($this->hasMany, $this->hasOne) as $assoc => $data) { - if ($data['dependent'] === true && $cascade === true) { - - $model = $this->{$assoc}; - $conditions = array($model->escapeField($data['foreignKey']) => $id); - if ($data['conditions']) { - $conditions = array_merge((array)$data['conditions'], $conditions); - } - $model->recursive = -1; + 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; - 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]); + } } } }