@@ -109,7 +109,7 @@ class QueryResultTypeWalker extends SqlWalker
109
109
private $ hasGroupByClause ;
110
110
111
111
/** @var bool */
112
- private $ hasCondition ;
112
+ private $ hasWhereClause ;
113
113
114
114
/**
115
115
* @param Query<mixed> $query
@@ -139,7 +139,7 @@ public function __construct($query, $parserResult, array $queryComponents)
139
139
$ this ->nullableQueryComponents = [];
140
140
$ this ->hasAggregateFunction = false ;
141
141
$ this ->hasGroupByClause = false ;
142
- $ this ->hasCondition = false ;
142
+ $ this ->hasWhereClause = false ;
143
143
144
144
// The object is instantiated by Doctrine\ORM\Query\Parser, so receiving
145
145
// dependencies through the constructor is not an option. Instead, we
@@ -179,6 +179,7 @@ public function walkSelectStatement(AST\SelectStatement $AST): string
179
179
$ this ->typeBuilder ->setSelectQuery ();
180
180
$ this ->hasAggregateFunction = $ this ->hasAggregateFunction ($ AST );
181
181
$ this ->hasGroupByClause = $ AST ->groupByClause !== null ;
182
+ $ this ->hasWhereClause = $ AST ->whereClause !== null ;
182
183
183
184
$ this ->walkFromClause ($ AST ->fromClause );
184
185
@@ -596,8 +597,6 @@ public function walkOrderByItem($orderByItem): string
596
597
*/
597
598
public function walkHavingClause ($ havingClause ): string
598
599
{
599
- $ this ->hasCondition = true ;
600
-
601
600
return $ this ->marshalType (new MixedType ());
602
601
}
603
602
@@ -1033,8 +1032,6 @@ public function walkWhereClause($whereClause): string
1033
1032
*/
1034
1033
public function walkConditionalExpression ($ condExpr ): string
1035
1034
{
1036
- $ this ->hasCondition = true ;
1037
-
1038
1035
return $ this ->marshalType (new MixedType ());
1039
1036
}
1040
1037
@@ -1322,10 +1319,10 @@ public function walkResultVariable($resultVariable): string
1322
1319
*/
1323
1320
private function addScalar ($ alias , Type $ type ): void
1324
1321
{
1325
- // Since we don't check the condition inside the WHERE or HAVING
1322
+ // Since we don't check the condition inside the WHERE
1326
1323
// conditions, we cannot be sure all the union types are correct.
1327
1324
// For exemple, a condition `WHERE foo.bar IS NOT NULL` could be added.
1328
- if ($ this ->hasCondition && $ type instanceof UnionType) {
1325
+ if ($ this ->hasWhereClause && $ type instanceof UnionType) {
1329
1326
$ type = TypeUtils::toBenevolentUnion ($ type );
1330
1327
}
1331
1328
0 commit comments