Skip to content

Commit

Permalink
Don't hydrate empty association entities.
Browse files Browse the repository at this point in the history
When hasOne/belongsTo (joinable associations) are empty we should skip
populating empty entities as they cause problems later on in the
request.

Refs #3806
Refs #3902
  • Loading branch information
markstory committed Jul 9, 2014
1 parent da2af6d commit 3410911
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ORM/ResultSet.php
Expand Up @@ -400,14 +400,21 @@ protected function _groupResult($row) {

if ($assoc['canBeJoined']) {
$results[$alias] = $this->_castValues($target, $results[$alias]);

$hasData = array_filter($results[$alias], function ($v) {
return $v !== null;
});

if (!$hasData) {
continue;
}
}

if ($this->_hydrate && $assoc['canBeJoined']) {
$entity = new $assoc['entityClass']($results[$alias], $options);
$entity->clean();
$results[$alias] = $entity;
}

$results = $instance->transformRow($results, $alias, $assoc['canBeJoined']);
}

Expand Down

0 comments on commit 3410911

Please sign in to comment.