@@ -93,26 +93,23 @@ public function __construct($query, $parserResult, array $queryComponents)
9393 */
9494 public function walkSelectStatement (SelectStatement $ AST )
9595 {
96- if ($ this ->platform instanceof PostgreSqlPlatform) {
97- // Set every select expression as visible(hidden = false) to
98- // make $AST to have scalar mappings properly
99- $ hiddens = array ();
100- foreach ($ AST ->selectClause ->selectExpressions as $ idx => $ expr ) {
101- $ hiddens [$ idx ] = $ expr ->hiddenAliasResultVariable ;
102- $ expr ->hiddenAliasResultVariable = false ;
103- }
96+ // Set every select expression as visible(hidden = false) to
97+ // make $AST have scalar mappings properly - this is relevant for referencing selected
98+ // fields from outside the subquery, for example in the ORDER BY segment
99+ $ hiddens = array ();
100+
101+ foreach ($ AST ->selectClause ->selectExpressions as $ idx => $ expr ) {
102+ $ hiddens [$ idx ] = $ expr ->hiddenAliasResultVariable ;
103+ $ expr ->hiddenAliasResultVariable = false ;
104+ }
104105
105- $ innerSql = parent ::walkSelectStatement ($ AST );
106+ $ innerSql = parent ::walkSelectStatement ($ AST );
106107
107- // Restore hiddens
108- foreach ($ AST ->selectClause ->selectExpressions as $ idx => $ expr ) {
109- $ expr ->hiddenAliasResultVariable = $ hiddens [$ idx ];
110- }
111- } else {
112- $ innerSql = parent ::walkSelectStatement ($ AST );
108+ // Restore hiddens
109+ foreach ($ AST ->selectClause ->selectExpressions as $ idx => $ expr ) {
110+ $ expr ->hiddenAliasResultVariable = $ hiddens [$ idx ];
113111 }
114112
115-
116113 // Find out the SQL alias of the identifier column of the root entity.
117114 // It may be possible to make this work with multiple root entities but that
118115 // would probably require issuing multiple queries or doing a UNION SELECT.
0 commit comments