fixes #4790, restoring associations in Containable. Thanks to maular for the patch

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7245 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-06-23 04:41:15 +00:00
parent 9661a54a13
commit ca38b035b5
2 changed files with 122 additions and 120 deletions

View file

@ -134,6 +134,14 @@ class ContainableBehavior extends ModelBehavior {
if (!isset($model['keep'][$assoc])) {
$unbind[] = $assoc;
}
}
if ($unbind) {
if (!$reset && empty($instance->__backOriginalAssociation)) {
$instance->__backOriginalAssociation = $backupBindings;
}
$instance->unbindModel(array($type => $unbind), $reset);
}
foreach ($instance->{$type} as $assoc => $options) {
if (isset($model['keep'][$assoc]) && !empty($model['keep'][$assoc])) {
if (isset($model['keep'][$assoc]['fields'])) {
$model['keep'][$assoc]['fields'] = $this->fieldDependencies($containments['models'][$assoc]['instance'], $map, $model['keep'][$assoc]['fields']);
@ -149,12 +157,6 @@ class ContainableBehavior extends ModelBehavior {
$instance->__backInnerAssociation[] = $assoc;
}
}
if ($unbind) {
if (!$reset && empty($instance->__backOriginalAssociation)) {
$instance->__backOriginalAssociation = $backupBindings;
}
$instance->unbindModel(array($type => $unbind), $reset);
}
}
}
}

View file

@ -3204,7 +3204,7 @@ class ContainableTest extends CakeTestCase {
$options = array(
'conditions' => array(
'Comment.comment' => '!= Crazy',
'Comment.comment !=' => 'Crazy',
'Comment.published' => 'Y',
),
'contain' => 'User',
@ -3215,7 +3215,7 @@ class ContainableTest extends CakeTestCase {
$dummyResult = $this->Article->Comment->find('all', array(
'conditions' => array(
'Comment.comment' => '!= Silly',
'Comment.comment !=' => 'Silly',
'User.user' => 'mariano'
),
'fields' => array('User.password'),