diff --git a/lib/Doctrine/Hydrator/Graph.php b/lib/Doctrine/Hydrator/Graph.php index 8578f4871..b227f3874 100644 --- a/lib/Doctrine/Hydrator/Graph.php +++ b/lib/Doctrine/Hydrator/Graph.php @@ -311,11 +311,17 @@ protected function _gatherRowData(&$data, &$cache, &$id, &$nonemptyComponents) $table = $this->_queryComponents[$cache[$key]['dqlAlias']]['table']; $fieldName = $table->getFieldName($last); $cache[$key]['fieldName'] = $fieldName; + + if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg_field'][$last])) { + $fieldName = $this->_queryComponents[$cache[$key]['dqlAlias']]['agg_field'][$last]; + } + if ($table->isIdentifier($fieldName)) { $cache[$key]['isIdentifier'] = true; } else { $cache[$key]['isIdentifier'] = false; } + $type = $table->getTypeOfColumn($last); if ($type == 'integer' || $type == 'string') { $cache[$key]['isSimpleType'] = true; diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index c446274d3..a4d0b40f8 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -648,6 +648,10 @@ public function parseSelect($dql) $this->_queryComponents[$componentAlias]['agg'][$index] = $alias; + if (preg_match('/^([^\(]+)\.(\'?)(.*?)(\'?)$/', $expression, $field)) { + $this->_queryComponents[$componentAlias]['agg_field'][$index] = $field[3]; + } + $this->_neededTables[] = $tableAlias; } else { $e = explode('.', $terms[0]); diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index 6042ed18e..247886f1c 100644 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -206,6 +206,16 @@ abstract class Doctrine_Query_Abstract * * map the name of the column / aggregate value this * component is mapped to a collection + * + * agg_field the field names for each aggregates + * Example: + * DQL: COMPONENT.FIELD as ALIAS + * SQL: TABLE.COLUMN as TABLE__0 + * $_queryComponents + * agg: + * 0: ALIAS + * agg_field: + * 0: FIELD */ protected $_queryComponents = array(); @@ -1259,6 +1269,9 @@ protected function _constructQueryFromCache($cached) if (isset($components['agg'])) { $queryComponents[$alias]['agg'] = $components['agg']; } + if (isset($components['agg_field'])) { + $queryComponents[$alias]['agg_field'] = $components['agg_field']; + } if (isset($components['map'])) { $queryComponents[$alias]['map'] = $components['map']; } @@ -1289,6 +1302,9 @@ public function getCachedForm($customComponent = null) if (isset($components['agg'])) { $componentInfo[$alias]['agg'] = $components['agg']; } + if (isset($components['agg_field'])) { + $componentInfo[$alias]['agg_field'] = $components['agg_field']; + } if (isset($components['map'])) { $componentInfo[$alias]['map'] = $components['map']; }