Skip to content

Commit

Permalink
only add relation identifier when at least one relation column is sel…
Browse files Browse the repository at this point in the history
…ected
  • Loading branch information
alquerci committed Apr 17, 2024
1 parent fb19b38 commit 7b6763b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/Doctrine/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,8 @@ public function parseSelect($dql)
$this->_expressionMap[$alias][0] = $expression;

$this->_queryComponents[$componentAlias]['agg'][$index] = $alias;
$this->_queryComponents[$componentAlias]['has_selected_column'] ??= false;
$this->_queryComponents[$componentAlias]['has_selected_column'] |= $pos === false;

if (preg_match('/^([^\(]+)\.(\'?)(.*?)(\'?)$/', $expression, $field)) {
$this->_queryComponents[$componentAlias]['agg_field'][$index] = $field[3];
Expand Down Expand Up @@ -682,7 +684,11 @@ private function appendRelationIdentifierOnSqlSelect()

if ($shouldSelectRelationIdentifier) {
foreach ($this->_queryComponents as $componentAlias => $queryComponent) {
if (isset($queryComponent['relation']) && isset($queryComponent['agg'])) {
if (
isset($queryComponent['relation'])
&& isset($queryComponent['agg'])
&& !empty($queryComponent['has_selected_column'])
) {
$table = $queryComponent['table'];

foreach ((array) $table->getIdentifier() as $field) {
Expand Down

0 comments on commit 7b6763b

Please sign in to comment.