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
This commit is contained in:
phpnut 2006-11-23 11:31:59 +00:00
parent 2e0ec28018
commit fd65f226e6

View file

@ -1159,6 +1159,10 @@ class Model extends Overloadable {
* @access protected * @access protected
*/ */
function _deleteHasMany($id, $cascade) { function _deleteHasMany($id, $cascade) {
if (isset($this->__backAssociation)) {
$savedAssociatons = $this->__backAssociation;
unset ($this->__backAssociation);
}
foreach($this->hasMany as $assoc => $data) { foreach($this->hasMany as $assoc => $data) {
if ($data['dependent'] === true && $cascade === true) { if ($data['dependent'] === true && $cascade === true) {
$model =& $this->{$data['className']}; $model =& $this->{$data['className']};
@ -1173,6 +1177,9 @@ class Model extends Overloadable {
} }
} }
} }
if (isset($savedAssociatons)) {
$this->__backAssociation = $savedAssociatons;
}
} }
/** /**
* Cascades model deletes to hasOne relationships. * Cascades model deletes to hasOne relationships.
@ -1182,6 +1189,10 @@ class Model extends Overloadable {
* @access protected * @access protected
*/ */
function _deleteHasOne($id, $cascade) { function _deleteHasOne($id, $cascade) {
if (isset($this->__backAssociation)) {
$savedAssociatons = $this->__backAssociation;
unset ($this->__backAssociation);
}
foreach($this->hasOne as $assoc => $data) { foreach($this->hasOne as $assoc => $data) {
if ($data['dependent'] === true && $cascade === true) { if ($data['dependent'] === true && $cascade === true) {
$model =& $this->{$data['className']}; $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. * Cascades model deletes to HABTM join keys.