Skip to content

Commit

Permalink
fixup! fix: add failing test when aliasing a column of a joined relation
Browse files Browse the repository at this point in the history
  • Loading branch information
alquerci committed Apr 15, 2024
1 parent 6a0fe33 commit 0af3477
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Doctrine/Hydrator/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ protected function _gatherRowData(&$data, &$cache, &$id, &$nonemptyComponents)
$table = $this->_queryComponents[$cache[$key]['dqlAlias']]['table'];
$fieldName = $table->getFieldName($last);
$cache[$key]['fieldName'] = $fieldName;
$cache[$key]['isRelation'] = isset($this->_queryComponents[$cache[$key]['dqlAlias']]['relation']);

if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg_field'][$last])) {
$fieldName = $this->_queryComponents[$cache[$key]['dqlAlias']]['agg_field'][$last];
Expand Down Expand Up @@ -351,11 +352,19 @@ protected function _gatherRowData(&$data, &$cache, &$id, &$nonemptyComponents)
$preparedValue = $table->prepareValue($fieldName, $value, $cache[$key]['type']);
}


// Ticket #1380
// Hydrate aggregates in to the root component as well.
// So we know that all aggregate values will always be available in the root component
if ($agg) {
$rowData[$this->_rootAlias][$fieldName] = $preparedValue;

if (!isset($rowData[$dqlAlias])) {
if ($cache[$key]['isRelation'] && $this instanceof Doctrine_Hydrator_ArrayDriver) {
$rowData[$dqlAlias] = array();
}
}

if (isset($rowData[$dqlAlias])) {
$rowData[$dqlAlias][$fieldName] = $preparedValue;
}
Expand Down

0 comments on commit 0af3477

Please sign in to comment.