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:
AD7six 2008-08-01 16:49:56 +00:00
parent 5ff62650e5
commit 739c5169e4

View file

@ -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;
}
}