From fd65f226e6c1e0f2988d26e87f1948dfb7935325 Mon Sep 17 00:00:00 2001 From: phpnut Date: Thu, 23 Nov 2006 11:31:59 +0000 Subject: [PATCH] Adding fix for Ticket #1626. This fixes deleting of associated hasOne and hasMany when using bindModel before Model::delete() git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3941 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 9c5bbeec0..c0a6ac4a8 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1159,6 +1159,10 @@ class Model extends Overloadable { * @access protected */ function _deleteHasMany($id, $cascade) { + if (isset($this->__backAssociation)) { + $savedAssociatons = $this->__backAssociation; + unset ($this->__backAssociation); + } foreach($this->hasMany as $assoc => $data) { if ($data['dependent'] === true && $cascade === true) { $model =& $this->{$data['className']}; @@ -1173,6 +1177,9 @@ class Model extends Overloadable { } } } + if (isset($savedAssociatons)) { + $this->__backAssociation = $savedAssociatons; + } } /** * Cascades model deletes to hasOne relationships. @@ -1182,6 +1189,10 @@ class Model extends Overloadable { * @access protected */ function _deleteHasOne($id, $cascade) { + if (isset($this->__backAssociation)) { + $savedAssociatons = $this->__backAssociation; + unset ($this->__backAssociation); + } foreach($this->hasOne as $assoc => $data) { if ($data['dependent'] === true && $cascade === true) { $model =& $this->{$data['className']}; @@ -1196,6 +1207,9 @@ class Model extends Overloadable { } } } + if (isset($savedAssociatons)) { + $this->__backAssociation = $savedAssociatons; + } } /** * Cascades model deletes to HABTM join keys.