Skip to content

Commit

Permalink
Type casting conditions array to avoid warning during array merge in …
Browse files Browse the repository at this point in the history
…Model::_deleteDependent(). Fixes #477
  • Loading branch information
ADmad committed Mar 17, 2010
1 parent 93ac79d commit 6a723bb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cake/libs/model/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ function _deleteDependent($id, $cascade) {
$model =& $this->{$assoc};
$conditions = array($model->escapeField($data['foreignKey']) => $id);
if ($data['conditions']) {
$conditions = array_merge($data['conditions'], $conditions);
$conditions = array_merge((array)$data['conditions'], $conditions);
}
$model->recursive = -1;

Expand Down
11 changes: 11 additions & 0 deletions cake/tests/cases/libs/model/model_delete.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function testDeleteDependentWithConditions() {
$this->loadFixtures('Cd','Book','OverallFavorite');

$Cd =& new Cd();
$Book =& new Book();
$OverallFavorite =& new OverallFavorite();

$Cd->delete(1);
Expand All @@ -174,6 +175,16 @@ function testDeleteDependentWithConditions() {

$this->assertTrue(is_array($result));
$this->assertEqual($result, $expected);

$Book->delete(1);

$result = $OverallFavorite->find('all', array(
'fields' => array('model_type', 'model_id', 'priority')
));
$expected = array();

$this->assertTrue(is_array($result));
$this->assertEqual($result, $expected);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions cake/tests/cases/libs/model/models.php
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,7 @@ class AssociationTest2 extends CakeTestModel {
* @subpackage cake.tests.cases.libs.model
*/
class Callback extends CakeTestModel {

}
/**
* CallbackPostTestModel class
Expand Down Expand Up @@ -2445,7 +2445,7 @@ class Book extends CakeTestModel {
* @var array
* @access public
*/
var $hasOne = array('OverallFavorite' => array('foreignKey' => 'model_id', 'dependent' => true, 'conditions' => array('model_type' => 'Book')));
var $hasOne = array('OverallFavorite' => array('foreignKey' => 'model_id', 'dependent' => true, 'conditions' => 'OverallFavorite.model_type = \'Book\''));
}

/**
Expand Down

0 comments on commit 6a723bb

Please sign in to comment.