mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
fixes #5064 Preventing 'floating' results from being returned by find('threaded')
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7414 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
5ff62650e5
commit
739c5169e4
1 changed files with 15 additions and 1 deletions
|
@ -1975,6 +1975,9 @@ class Model extends Overloadable {
|
|||
/**
|
||||
* findThreaded method
|
||||
*
|
||||
* In the event of ambiguous results returned (multiple top level results, with different parent_ids)
|
||||
* top level results with different parent_ids to the first result will be dropped
|
||||
*
|
||||
* @param mixed $state
|
||||
* @param mixed $query
|
||||
* @param array $results
|
||||
|
@ -2003,6 +2006,17 @@ class Model extends Overloadable {
|
|||
$idMap[$parentId]['children'][] =& $idMap[$id];
|
||||
}
|
||||
}
|
||||
if (count($return) > 1) {
|
||||
$ids = array_unique(Set::extract('/' . $this->alias . '/parent_id', $return));
|
||||
if (count($ids) > 1) {
|
||||
$root = $return[0][$this->alias]['parent_id'];
|
||||
foreach ($return as $key => $value) {
|
||||
if ($value[$this->alias]['parent_id'] != $root) {
|
||||
unset ($return[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
@ -2664,4 +2678,4 @@ class Model extends Overloadable {
|
|||
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
||||
Overloadable::overload('Model');
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue