Move check out of the loop, and allow nulls.

Refs #2341
This commit is contained in:
mark_story 2012-01-10 20:15:59 -05:00
parent d238d8c0bb
commit a8bc916104

View file

@ -2815,16 +2815,17 @@ class Model extends Object implements CakeEventListener {
$return = $idMap = array();
$ids = Set::extract($results, '{n}.' . $this->alias . '.' . $this->primaryKey);
if (isset($results[0][$this->alias]) && !array_key_exists('parent_id', $results[0][$this->alias])) {
trigger_error(
__d('cake_dev', 'You cannot use find("threaded") on models without a "parent_id" field.'),
E_USER_WARNING
);
return $return;
}
foreach ($results as $result) {
$result['children'] = array();
$id = $result[$this->alias][$this->primaryKey];
if (!isset($result[$this->alias]['parent_id'])) {
trigger_error(
__d('cake_dev', 'You cannot use find("threaded") on models without a "parent_id" field.'),
E_USER_WARNING
);
return $return;
}
$parentId = $result[$this->alias]['parent_id'];
if (isset($idMap[$id]['children'])) {
$idMap[$id] = array_merge($result, (array)$idMap[$id]);