Permalink
Browse files

Added fields with alias to pendingFields array, fixed DC-585

  • Loading branch information...
1 parent df759df commit e3ae69c2260dae6dfbceb4e24138b2379f3da2e6 Juan Antonio Galan committed with jwage Aug 31, 2010
Showing with 17 additions and 3 deletions.
  1. +17 −3 lib/Doctrine/Query.php
View
@@ -484,7 +484,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()) {
@@ -496,10 +496,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;
}
}
@@ -651,6 +658,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]);

1 comment on commit e3ae69c

Contributor

estahn commented on e3ae69c Oct 15, 2010

Hi Juan,

where is the Unit-Test for this Issue? Any query using aliases in our application was broken. I will commit a patch for this but I can't guarantee that your patch is working afterwards cause of the missing unit test.

Enrico

Please sign in to comment.