Skip to content

Commit

Permalink
Revert "Revert "Added fields with alias to pendingFields array, fixed…
Browse files Browse the repository at this point in the history
… DC-585""

This reverts commit 29961c7.
  • Loading branch information
alquerci committed Apr 15, 2024
1 parent 7632657 commit 5596999
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/Doctrine/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ public function processPendingFields($componentAlias)
}

$sql = array();
foreach ($fields as $fieldName) {
foreach ($fields as $fieldAlias => $fieldName) {
$columnName = $table->getColumnName($fieldName);
if (($owner = $table->getColumnOwner($columnName)) !== null &&
$owner !== $table->getComponentName()) {
Expand All @@ -492,10 +492,17 @@ public function processPendingFields($componentAlias)
. ' AS '
. $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName);
} else {
$columnName = $table->getColumnName($fieldName);
// Fix for http://www.doctrine-project.org/jira/browse/DC-585
// Take the field alias if available
if (isset($this->_aggregateAliasMap[$fieldAlias])) {
$aliasSql = $this->_aggregateAliasMap[$fieldAlias];
} else {
$columnName = $table->getColumnName($fieldName);
$aliasSql = $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName);
}
$sql[] = $this->_conn->quoteIdentifier($tableAlias) . '.' . $this->_conn->quoteIdentifier($columnName)
. ' AS '
. $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName);
. $aliasSql;
}
}

Expand Down Expand Up @@ -649,6 +656,13 @@ public function parseSelect($dql)
$this->_queryComponents[$componentAlias]['agg'][$index] = $alias;

$this->_neededTables[] = $tableAlias;

// Fix for http://www.doctrine-project.org/jira/browse/DC-585
// Add selected columns to pending fields
if (preg_match('/^([^\(]+)\.(\'?)(.*?)(\'?)$/', $expression, $field)) {
$this->_pendingFields[$componentAlias][$alias] = $field[3];
}

} else {
$e = explode('.', $terms[0]);

Expand Down

0 comments on commit 5596999

Please sign in to comment.