Skip to content

Commit

Permalink
Fixing issue in Containable where if bindModel was used to add / chan…
Browse files Browse the repository at this point in the history
…ge a binding not permanently, Containable was making the change permanent
  • Loading branch information
mariano committed Mar 14, 2010
1 parent 239e34f commit 8d58b40
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cake/libs/model/behaviors/containable.php
Expand Up @@ -129,7 +129,11 @@ function beforeFind(&$Model, $query) {
if ($contain) {
$backupBindings = array();
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) {
$unbind = array();
Expand Down
25 changes: 25 additions & 0 deletions cake/tests/cases/libs/model/behaviors/containable.test.php
Expand Up @@ -3311,6 +3311,31 @@ function testOriginalAssociations() {
$this->assertTrue(Set::matches('/Comment[article_id=1]', $result));
$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
*
Expand Down

0 comments on commit 8d58b40

Please sign in to comment.