@@ -106,6 +106,9 @@ class QueryResultTypeWalker extends SqlWalker
106
106
/** @var bool */
107
107
private $ hasGroupByClause ;
108
108
109
+ /** @var bool */
110
+ private $ hasCondition ;
111
+
109
112
/**
110
113
* @param Query<mixed> $query
111
114
*/
@@ -134,6 +137,7 @@ public function __construct($query, $parserResult, array $queryComponents)
134
137
$ this ->nullableQueryComponents = [];
135
138
$ this ->hasAggregateFunction = false ;
136
139
$ this ->hasGroupByClause = false ;
140
+ $ this ->hasCondition = false ;
137
141
138
142
// The object is instantiated by Doctrine\ORM\Query\Parser, so receiving
139
143
// dependencies through the constructor is not an option. Instead, we
@@ -589,6 +593,8 @@ public function walkOrderByItem($orderByItem)
589
593
*/
590
594
public function walkHavingClause ($ havingClause )
591
595
{
596
+ $ this ->hasCondition = true ;
597
+
592
598
return $ this ->marshalType (new MixedType ());
593
599
}
594
600
@@ -993,6 +999,8 @@ public function walkUpdateItem($updateItem)
993
999
*/
994
1000
public function walkWhereClause ($ whereClause )
995
1001
{
1002
+ $ this ->hasCondition = true ;
1003
+
996
1004
return $ this ->marshalType (new MixedType ());
997
1005
}
998
1006
@@ -1280,7 +1288,7 @@ public function walkResultVariable($resultVariable)
1280
1288
*/
1281
1289
private function addScalar ($ alias , Type $ type ): void
1282
1290
{
1283
- if ($ type instanceof UnionType) {
1291
+ if ($ this -> hasCondition && $ type instanceof UnionType) {
1284
1292
$ type = TypeUtils::toBenevolentUnion ($ type );
1285
1293
}
1286
1294
0 commit comments