diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index c2ee2137e..e5b9f69ca 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -125,11 +125,6 @@ class Parser */ private $_customOutputWalker; - /** - * @var array - */ - private $_identVariableOrder = array(); - /** * @var array */ @@ -307,12 +302,14 @@ class Parser } } - // fix order of identification variables + // Fix order of identification variables. + // They have to appear in the select clause in the same order as the + // declarations (from ... x join ... y join ... z ...) appear in the query + // as the hydration process relies on that order for proper operation. if ( count($this->_identVariableExpressions) > 1) { - $n = count($this->_identVariableOrder); - for ($i = 0; $i < $n; $i++) { - if (isset($this->_identVariableExpressions[$this->_identVariableOrder[$i]])) { - $expr = $this->_identVariableExpressions[$this->_identVariableOrder[$i]]; + foreach ($this->_queryComponents as $dqlAlias => $qComp) { + if (isset($this->_identVariableExpressions[$dqlAlias])) { + $expr = $this->_identVariableExpressions[$dqlAlias]; $key = array_search($expr, $AST->selectClause->selectExpressions); unset($AST->selectClause->selectExpressions[$key]); $AST->selectClause->selectExpressions[] = $expr; @@ -1442,7 +1439,6 @@ class Parser $token = $this->_lexer->lookahead; $aliasIdentificationVariable = $this->AliasIdentificationVariable(); - $this->_identVariableOrder[] = $aliasIdentificationVariable; $classMetadata = $this->_em->getClassMetadata($abstractSchemaName); // Building queryComponent @@ -1533,7 +1529,6 @@ class Parser $token = $this->_lexer->lookahead; $aliasIdentificationVariable = $this->AliasIdentificationVariable(); - $this->_identVariableOrder[] = $aliasIdentificationVariable; // Verify that the association exists. $parentClass = $this->_queryComponents[$joinPathExpression->identificationVariable]['metadata']; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php index e6138f87d..0c8b764a2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php @@ -32,11 +32,15 @@ class DDC736Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->_em->clear(); - $cart2 = $this->_em->createQuery("select c, ca from Doctrine\Tests\Models\ECommerce\ECommerceCart ca join ca.customer c") + $result = $this->_em->createQuery("select c, c.name, ca, ca.payment from Doctrine\Tests\Models\ECommerce\ECommerceCart ca join ca.customer c") ->getSingleResult(/*\Doctrine\ORM\Query::HYDRATE_ARRAY*/); + + $cart2 = $result[0]; + unset($result[0]); - $this->assertTrue($cart2 instanceof ECommerceCart); - $this->assertFalse($cart2->getCustomer() instanceof \Doctrine\ORM\Proxy\Proxy); - $this->assertTrue($cart2->getCustomer() instanceof ECommerceCustomer); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCart', $cart2); + $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $cart2->getCustomer()); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $cart2->getCustomer()); + $this->assertEquals(array('name' => 'roman', 'payment' => 'cash'), $result); } }