diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 150ab077f..c4a17ec7b 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -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'); } -?> \ No newline at end of file +?>