mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-17 06:59:51 +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
|
* @access public
|
||||||
*/
|
*/
|
||||||
function beforeFind(&$Model, $query) {
|
function beforeFind(&$Model, $query) {
|
||||||
$reset = true;
|
$reset = (isset($query['reset']) ? $query['reset'] : true);
|
||||||
if (isset($query['reset'])) {
|
|
||||||
$reset = $query['reset'];
|
|
||||||
}
|
|
||||||
$noContain = ((isset($this->runtime[$Model->alias]['contain']) && empty($this->runtime[$Model->alias]['contain'])) || (isset($query['contain']) && empty($query['contain'])));
|
$noContain = ((isset($this->runtime[$Model->alias]['contain']) && empty($this->runtime[$Model->alias]['contain'])) || (isset($query['contain']) && empty($query['contain'])));
|
||||||
$contain = array();
|
$contain = array();
|
||||||
if (isset($this->runtime[$Model->alias]['contain'])) {
|
if (isset($this->runtime[$Model->alias]['contain'])) {
|
||||||
|
@ -271,7 +268,7 @@ class ContainableBehavior extends ModelBehavior {
|
||||||
|
|
||||||
$keys = array_keys($children);
|
$keys = array_keys($children);
|
||||||
if ($keys && isset($children[0])) {
|
if ($keys && isset($children[0])) {
|
||||||
$keys = am(array_values($children), $keys);
|
$keys = array_merge(array_values($children), $keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($keys as $i => $key) {
|
foreach ($keys as $i => $key) {
|
||||||
|
@ -304,7 +301,11 @@ class ContainableBehavior extends ModelBehavior {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($optionKey && isset($children[$key])) {
|
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]);
|
$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]);
|
unset($children[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,12 @@ class ContainableTest extends CakeTestCase {
|
||||||
$this->assertEqual(Set::extract('/Article/keep/User/fields', $r), array('user'));
|
$this->assertEqual(Set::extract('/Article/keep/User/fields', $r), array('user'));
|
||||||
$this->assertTrue(Set::matches('/Comment/keep/Attachment', $r));
|
$this->assertTrue(Set::matches('/Comment/keep/Attachment', $r));
|
||||||
$this->assertEqual(Set::extract('/Comment/keep/Attachment/fields', $r), array('attachment'));
|
$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() {
|
function testInvalidContainments() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue