mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-10 05:22:41 +00:00
Fixing cascading delete, when using foreignKey false and setting condition on hasOne.
This commit is contained in:
parent
87a8af420f
commit
b5c4b85601
6 changed files with 265 additions and 5 deletions
|
@ -2249,11 +2249,17 @@ class Model extends Object {
|
|||
if ($data['dependent'] === true) {
|
||||
|
||||
$model = $this->{$assoc};
|
||||
$conditions = array($model->escapeField($data['foreignKey']) => $id);
|
||||
if ($data['conditions']) {
|
||||
$conditions = array_merge((array)$data['conditions'], $conditions);
|
||||
|
||||
if ($data['foreignKey'] === false && $data['conditions'] && in_array($this->name, $model->getAssociated('belongsTo'))) {
|
||||
$model->recursive = 0;
|
||||
$conditions = array($this->escapeField(null, $this->name) => $id);
|
||||
} else {
|
||||
$model->recursive = -1;
|
||||
$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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue