mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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:
parent
a51cceab18
commit
1120d0daff
2 changed files with 30 additions and 1 deletions
|
@ -130,7 +130,11 @@ class ContainableBehavior extends ModelBehavior {
|
|||
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();
|
||||
|
|
|
@ -3327,6 +3327,31 @@ class ContainableBehaviorTest extends CakeTestCase {
|
|||
$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
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue