Skip to content

Commit 33bebf2

Browse files
alquercithePanz
authored andcommitted
fixup! fix(Query): column added twice with custom aliases
1 parent 29961c7 commit 33bebf2

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

lib/Doctrine/Hydrator/Graph.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,17 @@ protected function _gatherRowData(&$data, &$cache, &$id, &$nonemptyComponents)
311311
$table = $this->_queryComponents[$cache[$key]['dqlAlias']]['table'];
312312
$fieldName = $table->getFieldName($last);
313313
$cache[$key]['fieldName'] = $fieldName;
314+
315+
if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg_field'][$last])) {
316+
$fieldName = $this->_queryComponents[$cache[$key]['dqlAlias']]['agg_field'][$last];
317+
}
318+
314319
if ($table->isIdentifier($fieldName)) {
315320
$cache[$key]['isIdentifier'] = true;
316321
} else {
317322
$cache[$key]['isIdentifier'] = false;
318323
}
324+
319325
$type = $table->getTypeOfColumn($last);
320326
if ($type == 'integer' || $type == 'string') {
321327
$cache[$key]['isSimpleType'] = true;

lib/Doctrine/Query.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,10 @@ public function parseSelect($dql)
648648

649649
$this->_queryComponents[$componentAlias]['agg'][$index] = $alias;
650650

651+
if (preg_match('/^([^\(]+)\.(\'?)(.*?)(\'?)$/', $expression, $field)) {
652+
$this->_queryComponents[$componentAlias]['agg_field'][$index] = $field[3];
653+
}
654+
651655
$this->_neededTables[] = $tableAlias;
652656
} else {
653657
$e = explode('.', $terms[0]);

lib/Doctrine/Query/Abstract.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ abstract class Doctrine_Query_Abstract
206206
*
207207
* map the name of the column / aggregate value this
208208
* component is mapped to a collection
209+
*
210+
* agg_field the field names for each aggregates
211+
* Example:
212+
* DQL: COMPONENT.FIELD as ALIAS
213+
* SQL: TABLE.COLUMN as TABLE__0
214+
* $_queryComponents
215+
* agg:
216+
* 0: ALIAS
217+
* agg_field:
218+
* 0: FIELD
209219
*/
210220
protected $_queryComponents = array();
211221

@@ -1259,6 +1269,9 @@ protected function _constructQueryFromCache($cached)
12591269
if (isset($components['agg'])) {
12601270
$queryComponents[$alias]['agg'] = $components['agg'];
12611271
}
1272+
if (isset($components['agg_field'])) {
1273+
$queryComponents[$alias]['agg_field'] = $components['agg_field'];
1274+
}
12621275
if (isset($components['map'])) {
12631276
$queryComponents[$alias]['map'] = $components['map'];
12641277
}
@@ -1289,6 +1302,9 @@ public function getCachedForm($customComponent = null)
12891302
if (isset($components['agg'])) {
12901303
$componentInfo[$alias]['agg'] = $components['agg'];
12911304
}
1305+
if (isset($components['agg_field'])) {
1306+
$componentInfo[$alias]['agg_field'] = $components['agg_field'];
1307+
}
12921308
if (isset($components['map'])) {
12931309
$componentInfo[$alias]['map'] = $components['map'];
12941310
}

0 commit comments

Comments
 (0)