Skip to content

Commit

Permalink
Normalized associated models in unbindModel.
Browse files Browse the repository at this point in the history
 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.
  • Loading branch information
ravage84 committed Oct 24, 2013
1 parent 45bd01f commit 3773311
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lib/Cake/Model/Model.php
Expand Up @@ -953,9 +953,11 @@ public function bindModel($params, $reset = true) {
* 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
Expand All @@ -967,7 +969,7 @@ public function unbindModel($params, $reset = true) {
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]);
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Model/ModelReadTest.php
Expand Up @@ -2181,10 +2181,10 @@ public function testRecursiveUnbind() {

$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');
Expand Down

0 comments on commit 3773311

Please sign in to comment.