Skip to content

Commit 5596999

Browse files
committed
Revert "Revert "Added fields with alias to pendingFields array, fixed DC-585""
This reverts commit 29961c7.
1 parent 7632657 commit 5596999

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/Doctrine/Query.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ public function processPendingFields($componentAlias)
480480
}
481481

482482
$sql = array();
483-
foreach ($fields as $fieldName) {
483+
foreach ($fields as $fieldAlias => $fieldName) {
484484
$columnName = $table->getColumnName($fieldName);
485485
if (($owner = $table->getColumnOwner($columnName)) !== null &&
486486
$owner !== $table->getComponentName()) {
@@ -492,10 +492,17 @@ public function processPendingFields($componentAlias)
492492
. ' AS '
493493
. $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName);
494494
} else {
495-
$columnName = $table->getColumnName($fieldName);
495+
// Fix for http://www.doctrine-project.org/jira/browse/DC-585
496+
// Take the field alias if available
497+
if (isset($this->_aggregateAliasMap[$fieldAlias])) {
498+
$aliasSql = $this->_aggregateAliasMap[$fieldAlias];
499+
} else {
500+
$columnName = $table->getColumnName($fieldName);
501+
$aliasSql = $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName);
502+
}
496503
$sql[] = $this->_conn->quoteIdentifier($tableAlias) . '.' . $this->_conn->quoteIdentifier($columnName)
497504
. ' AS '
498-
. $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName);
505+
. $aliasSql;
499506
}
500507
}
501508

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

651658
$this->_neededTables[] = $tableAlias;
659+
660+
// Fix for http://www.doctrine-project.org/jira/browse/DC-585
661+
// Add selected columns to pending fields
662+
if (preg_match('/^([^\(]+)\.(\'?)(.*?)(\'?)$/', $expression, $field)) {
663+
$this->_pendingFields[$componentAlias][$alias] = $field[3];
664+
}
665+
652666
} else {
653667
$e = explode('.', $terms[0]);
654668

0 commit comments

Comments
 (0)