Skip to content

Commit 3773311

Browse files
committed
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.
1 parent 45bd01f commit 3773311

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/Cake/Model/Model.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,9 +953,11 @@ public function bindModel($params, $reset = true) {
953953
* Example: Turn off the associated Model Support request,
954954
* to temporarily lighten the User model:
955955
*
956-
* `$this->User->unbindModel( array('hasMany' => array('Supportrequest')) );`
956+
* `$this->User->unbindModel(array('hasMany' => array('SupportRequest')));`
957+
* Or alternatively:
958+
* `$this->User->unbindModel(array('hasMany' => 'SupportRequest'));`
957959
*
958-
* unbound models that are not made permanent will reset with the next call to Model::find()
960+
* Unbound models that are not made permanent will reset with the next call to Model::find()
959961
*
960962
* @param array $params Set of bindings to unbind (indexed by binding type)
961963
* @param boolean $reset Set to false to make the unbinding permanent
@@ -967,7 +969,7 @@ public function unbindModel($params, $reset = true) {
967969
if ($reset === true && !isset($this->__backAssociation[$assoc])) {
968970
$this->__backAssociation[$assoc] = $this->{$assoc};
969971
}
970-
972+
$models = Hash::normalize((array)$models, false);
971973
foreach ($models as $model) {
972974
if ($reset === false && isset($this->__backAssociation[$assoc][$model])) {
973975
unset($this->__backAssociation[$assoc][$model]);

lib/Cake/Test/Case/Model/ModelReadTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,10 +2181,10 @@ public function testRecursiveUnbind() {
21812181

21822182
$this->assertEquals($expected, $result);
21832183

2184-
$result = $TestModel->unbindModel(array('hasMany' => array('Child')));
2184+
$result = $TestModel->unbindModel(array('hasMany' => 'Child'));
21852185
$this->assertTrue($result);
21862186

2187-
$result = $TestModel->Sample->unbindModel(array('belongsTo' => array('Apple')));
2187+
$result = $TestModel->Sample->unbindModel(array('belongsTo' => 'Apple'));
21882188
$this->assertTrue($result);
21892189

21902190
$result = $TestModel->find('all');

0 commit comments

Comments
 (0)