Properly setting non-array option overrides, fixes #4732

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7008 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2008-05-22 14:22:12 +00:00
parent 8dc7515045
commit ea94b57ec1
2 changed files with 14 additions and 7 deletions

View file

@ -92,10 +92,7 @@ class ContainableBehavior extends ModelBehavior {
* @access public
*/
function beforeFind(&$Model, $query) {
$reset = true;
if (isset($query['reset'])) {
$reset = $query['reset'];
}
$reset = (isset($query['reset']) ? $query['reset'] : true);
$noContain = ((isset($this->runtime[$Model->alias]['contain']) && empty($this->runtime[$Model->alias]['contain'])) || (isset($query['contain']) && empty($query['contain'])));
$contain = array();
if (isset($this->runtime[$Model->alias]['contain'])) {
@ -265,13 +262,13 @@ class ContainableBehavior extends ModelBehavior {
$children = (array)$children;
foreach ($children as $key => $val) {
if (is_string($key) && is_string($val) && !in_array($key, $options, true)) {
$children[$key] = (array)$val;
$children[$key] = (array) $val;
}
}
$keys = array_keys($children);
if ($keys && isset($children[0])) {
$keys = am(array_values($children), $keys);
$keys = array_merge(array_values($children), $keys);
}
foreach ($keys as $i => $key) {
@ -304,7 +301,11 @@ class ContainableBehavior extends ModelBehavior {
}
}
if ($optionKey && isset($children[$key])) {
$keep[$name][$key] = array_merge((isset($keep[$name][$key]) ? $keep[$name][$key] : array()), (array) $children[$key]);
if (!empty($keep[$name][$key]) && is_array($keep[$name][$key])) {
$keep[$name][$key] = array_merge((isset($keep[$name][$key]) ? $keep[$name][$key] : array()), (array) $children[$key]);
} else {
$keep[$name][$key] = $children[$key];
}
unset($children[$key]);
}
}

View file

@ -105,6 +105,12 @@ class ContainableTest extends CakeTestCase {
$this->assertEqual(Set::extract('/Article/keep/User/fields', $r), array('user'));
$this->assertTrue(Set::matches('/Comment/keep/Attachment', $r));
$this->assertEqual(Set::extract('/Comment/keep/Attachment/fields', $r), array('attachment'));
$r = $this->__containments($this->Article, array('Comment' => array('limit' => 1)));
$this->assertEqual(array_keys($r), array('Comment', 'Article'));
$this->assertEqual(array_shift(Set::extract('/Comment/keep', $r)), array('keep' => array()));
$this->assertTrue(Set::matches('/Article/keep/Comment', $r));
$this->assertEqual(array_shift(Set::extract('/Article/keep/Comment/.', $r)), array('limit' => 1));
}
function testInvalidContainments() {