Skip to content
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...
1 parent 239e34f commit 8d58b40642c182afe307d00debf44a1dbd8a3c62 @mariano mariano committed
View
6 cake/libs/model/behaviors/containable.php
@@ -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();
View
25 cake/tests/cases/libs/model/behaviors/containable.test.php
@@ -3312,6 +3312,31 @@ function testOriginalAssociations() {
$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
*
* @access public

0 comments on commit 8d58b40

Please sign in to comment.
Something went wrong with that request. Please try again.