Skip to content

Commit

Permalink
fixup! fix(Query): column added twice with custom aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
alquerci authored and thePanz committed Jan 22, 2024
1 parent 29961c7 commit 33bebf2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Doctrine/Hydrator/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
16 changes: 16 additions & 0 deletions lib/Doctrine/Query/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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'];
}
Expand Down Expand Up @@ -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'];
}
Expand Down

0 comments on commit 33bebf2

Please sign in to comment.