mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing issue where non-reset associations would get reset by resetAssociations if __backAssociations existed. Test cases from 'real34' added. Fixes #868
This commit is contained in:
parent
8581350d24
commit
17a7a96ba2
2 changed files with 43 additions and 5 deletions
|
@ -532,7 +532,6 @@ class Model extends Overloadable {
|
|||
if ($reset === true) {
|
||||
$this->__backAssociation[$assoc] = $this->{$assoc};
|
||||
}
|
||||
|
||||
foreach ($model as $key => $value) {
|
||||
$assocName = $key;
|
||||
|
||||
|
@ -542,6 +541,10 @@ class Model extends Overloadable {
|
|||
}
|
||||
$modelName = $assocName;
|
||||
$this->{$assoc}[$assocName] = $value;
|
||||
|
||||
if ($reset === false && isset($this->__backAssociation[$assoc])) {
|
||||
$this->__backAssociation[$assoc][$assocName] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->__createLinks();
|
||||
|
@ -2341,9 +2344,9 @@ class Model extends Overloadable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Called only when bindTo<ModelName>() is used.
|
||||
* This resets the association arrays for the model back
|
||||
* to those originally defined in the model.
|
||||
* to those originally defined in the model. Normally called at the end
|
||||
* of each call to Model::find()
|
||||
*
|
||||
* @return boolean Success
|
||||
* @access public
|
||||
|
|
|
@ -4720,6 +4720,41 @@ class ModelReadTest extends BaseModelTest {
|
|||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testBindMultipleTimes method with different reset settings
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testBindMultipleTimesWithDifferentResetSettings() {
|
||||
$this->loadFixtures('User', 'Comment', 'Article');
|
||||
$TestModel =& new User();
|
||||
|
||||
$result = $TestModel->hasMany;
|
||||
$expected = array();
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $TestModel->bindModel(array(
|
||||
'hasMany' => array('Comment')
|
||||
));
|
||||
$this->assertTrue($result);
|
||||
$result = $TestModel->bindModel(
|
||||
array('hasMany' => array('Article')),
|
||||
false
|
||||
);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = array_keys($TestModel->hasMany);
|
||||
$expected = array('Comment', 'Article');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$TestModel->resetAssociations();
|
||||
|
||||
$result = array_keys($TestModel->hasMany);
|
||||
$expected = array('Article');
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that bindModel behaves with Custom primary Key associations
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue