Skip to content

Commit

Permalink
Move check out of the loop, and allow nulls.
Browse files Browse the repository at this point in the history
Refs #2341
  • Loading branch information
markstory committed Jan 11, 2012
1 parent d238d8c commit a8bc916
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/Cake/Model/Model.php
Expand Up @@ -2815,16 +2815,17 @@ protected function _findThreaded($state, $query, $results = array()) {
$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]);
Expand Down

0 comments on commit a8bc916

Please sign in to comment.