Normalized associated models in unbindModel.

Resolves #1764

 Had to cast $models to an array since ``Hash::normalize()`` doesn't support strings which ``Set::normalize()`` does (but which is deprecated).
 Reused existing tests.
This commit is contained in:
Marc Würth 2013-10-24 15:13:22 +02:00
parent 45bd01fdc0
commit 3773311cc0
2 changed files with 7 additions and 5 deletions

View file

@ -953,9 +953,11 @@ class Model extends Object implements CakeEventListener {
* Example: Turn off the associated Model Support request,
* to temporarily lighten the User model:
*
* `$this->User->unbindModel( array('hasMany' => array('Supportrequest')) );`
* `$this->User->unbindModel(array('hasMany' => array('SupportRequest')));`
* Or alternatively:
* `$this->User->unbindModel(array('hasMany' => 'SupportRequest'));`
*
* unbound models that are not made permanent will reset with the next call to Model::find()
* Unbound models that are not made permanent will reset with the next call to Model::find()
*
* @param array $params Set of bindings to unbind (indexed by binding type)
* @param boolean $reset Set to false to make the unbinding permanent
@ -967,7 +969,7 @@ class Model extends Object implements CakeEventListener {
if ($reset === true && !isset($this->__backAssociation[$assoc])) {
$this->__backAssociation[$assoc] = $this->{$assoc};
}
$models = Hash::normalize((array)$models, false);
foreach ($models as $model) {
if ($reset === false && isset($this->__backAssociation[$assoc][$model])) {
unset($this->__backAssociation[$assoc][$model]);

View file

@ -2181,10 +2181,10 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result);
$result = $TestModel->unbindModel(array('hasMany' => array('Child')));
$result = $TestModel->unbindModel(array('hasMany' => 'Child'));
$this->assertTrue($result);
$result = $TestModel->Sample->unbindModel(array('belongsTo' => array('Apple')));
$result = $TestModel->Sample->unbindModel(array('belongsTo' => 'Apple'));
$this->assertTrue($result);
$result = $TestModel->find('all');