Browse Source

Skip hydrating associations when they are empty.

When all columns are null/[] the related entity should be skipped. While
the null case was added in 34109118c7a43a221b099e0527588ea3d265b694, the
case for associated entities with deeper non-joined associations that
are also empty was missed. By treating [] as empty we cover that case as
well.

Fixes #4804
Mark Story 11 years ago
parent
commit
703a6ddb8d
2 changed files with 6 additions and 2 deletions
  1. 4 1
      src/ORM/EagerLoader.php
  2. 2 1
      src/ORM/ResultSet.php

+ 4 - 1
src/ORM/EagerLoader.php

@@ -454,7 +454,6 @@ class EagerLoader {
 			);
 			$statement = new CallbackStatement($statement, $driver, $f);
 		}
-
 		return $statement;
 	}
 
@@ -510,6 +509,10 @@ class EagerLoader {
 		$keys = [];
 		while ($result = $statement->fetch('assoc')) {
 			foreach ($collectKeys as $parts) {
+				// Missed joins will have null in the results.
+				if ($parts[2] && !isset($result[$parts[1][0]])) {
+					continue;
+				}
 				if ($parts[2]) {
 					$keys[$parts[0]][] = $result[$parts[1][0]];
 					continue;

+ 2 - 1
src/ORM/ResultSet.php

@@ -390,6 +390,7 @@ class ResultSet implements ResultSetInterface {
 			$alias = $assoc['nestKey'];
 			$instance = $assoc['instance'];
 
+			// Doing this before we're sure the root assoc has data is the problem.
 			if (!isset($results[$alias])) {
 				$results = $instance->defaultRowValue($results, $assoc['canBeJoined']);
 				continue;
@@ -404,7 +405,7 @@ class ResultSet implements ResultSetInterface {
 
 				$hasData = false;
 				foreach ($results[$alias] as $v) {
-					if ($v !== null) {
+					if ($v !== null && $v !== []) {
 						$hasData = true;
 						break;
 					}