diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index c24fa40cc..16d9e1081 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1353,7 +1353,8 @@ class SqlWalker implements TreeWalker break; case ($expr instanceof AST\NewObjectExpression): - $sql .= $this->walkNewObject($expr); + $resultAlias = $selectExpression->fieldIdentificationVariable ?: null; + $sql .= $this->walkNewObject($expr,$resultAlias); break; default: @@ -1519,10 +1520,10 @@ class SqlWalker implements TreeWalker * * @return string The SQL. */ - public function walkNewObject($newObjectExpression) + public function walkNewObject($newObjectExpression, $newObjectResultAlias=null) { $sqlSelectExpressions = array(); - $objIndex = $this->newObjectCounter++; + $objIndex = $newObjectResultAlias?:$this->newObjectCounter++; foreach ($newObjectExpression->args as $argIndex => $e) { $resultAlias = $this->scalarResultCounter++;