Skip to content
Permalink
Browse files

Fixing issue in Containable where if bindModel was used to add / chan…

…ge a binding not permanently, Containable was making the change permanent
  • Loading branch information...
mariano committed Mar 14, 2010
1 parent 239e34f commit 8d58b40642c182afe307d00debf44a1dbd8a3c62
@@ -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();
@@ -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
*

0 comments on commit 8d58b40

Please sign in to comment.
You can’t perform that action at this time.