mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
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:
parent
8dc7515045
commit
ea94b57ec1
2 changed files with 14 additions and 7 deletions
|
@ -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])) {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Reference in a new issue