Fixing issue in Containable where if bindModel was used to add / change a binding not permanently, Containable was making the change permanent

This commit is contained in:
Mariano Iglesias 2010-03-14 16:34:57 -03:00
parent a51cceab18
commit 1120d0daff
2 changed files with 30 additions and 1 deletions

View file

@ -130,7 +130,11 @@ class ContainableBehavior extends ModelBehavior {
if ($contain) { if ($contain) {
$backupBindings = array(); $backupBindings = array();
foreach ($this->types as $relation) { foreach ($this->types as $relation) {
$backupBindings[$relation] = $instance->{$relation}; if (!empty($instance->__backAssociation[$relation])) {
$backupBindings[$relation] = $instance->__backAssociation[$relation];
} else {
$backupBindings[$relation] = $instance->{$relation};
}
} }
foreach ($this->types as $type) { foreach ($this->types as $type) {
$unbind = array(); $unbind = array();

View file

@ -3327,6 +3327,31 @@ class ContainableBehaviorTest extends CakeTestCase {
$this->Article->resetBindings(); $this->Article->resetBindings();
} }
/**
* testResetAddedAssociation method
*
* @access public
*/
function testResetAddedAssociation() {
$this->assertTrue(empty($this->Article->hasMany['ArticlesTag']));
$this->Article->bindModel(array(
'hasMany' => array('ArticlesTag')
));
$this->assertTrue(!empty($this->Article->hasMany['ArticlesTag']));
$result = $this->Article->find('first', array(
'conditions' => array('Article.id' => 1),
'contain' => array('ArticlesTag')
));
$expected = array('Article', 'ArticlesTag');
$this->assertTrue(!empty($result));
$this->assertEqual('First Article', $result['Article']['title']);
$this->assertTrue(!empty($result['ArticlesTag']));
$this->assertEqual($expected, array_keys($result));
$this->assertTrue(empty($this->Article->hasMany['ArticlesTag']));
}
/** /**
* testResetAssociation method * testResetAssociation method
* *