Skip to content
This repository
Browse code

Move check out of the loop, and allow nulls.

Refs #2341
  • Loading branch information...
commit a8bc91610486f763c94498a798056ced3c773419 1 parent d238d8c
Mark Story authored January 10, 2012

Showing 1 changed file with 8 additions and 7 deletions. Show diff stats Hide diff stats

  1. 15  lib/Cake/Model/Model.php
15  lib/Cake/Model/Model.php
@@ -2815,16 +2815,17 @@ protected function _findThreaded($state, $query, $results = array()) {
2815 2815
 			$return = $idMap = array();
2816 2816
 			$ids = Set::extract($results, '{n}.' . $this->alias . '.' . $this->primaryKey);
2817 2817
 
  2818
+			if (isset($results[0][$this->alias]) && !array_key_exists('parent_id', $results[0][$this->alias])) {
  2819
+				trigger_error(
  2820
+					__d('cake_dev', 'You cannot use find("threaded") on models without a "parent_id" field.'),
  2821
+					E_USER_WARNING
  2822
+				);
  2823
+				return $return;
  2824
+			}
  2825
+
2818 2826
 			foreach ($results as $result) {
2819 2827
 				$result['children'] = array();
2820 2828
 				$id = $result[$this->alias][$this->primaryKey];
2821  
-				if (!isset($result[$this->alias]['parent_id'])) {
2822  
-					trigger_error(
2823  
-						__d('cake_dev', 'You cannot use find("threaded") on models without a "parent_id" field.'),
2824  
-						E_USER_WARNING
2825  
-					);
2826  
-					return $return;
2827  
-				}
2828 2829
 				$parentId = $result[$this->alias]['parent_id'];
2829 2830
 				if (isset($idMap[$id]['children'])) {
2830 2831
 					$idMap[$id] = array_merge($result, (array)$idMap[$id]);

0 notes on commit a8bc916

Please sign in to comment.
Something went wrong with that request. Please try again.