Commit
When the model has no parent_id trigger a warning about the impending failure and return an empty result. Fixes #2341
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2818,6 +2818,13 @@ protected function _findThreaded($state, $query, $results = array()) { | |
foreach ($results as $result) { | ||
$result['children'] = array(); | ||
$id = $result[$this->alias][$this->primaryKey]; | ||
if (!isset($result[$this->alias]['parent_id'])) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
renan
Contributor
|
||
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]); | ||
|
Wouldn it be better to check for parent_id in schema in the before part, instead of doing this check within the foreach loop of results?