diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 5c721a1d5..912138208 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1049,7 +1049,7 @@ class Parser * Parses an arbitrary path expression and defers semantical validation * based on expected types. * - * PathExpression ::= IdentificationVariable "." identifier + * PathExpression ::= IdentificationVariable "." identifier [ ("." identifier)* ] * * @param integer $expectedTypes * @@ -1065,6 +1065,12 @@ class Parser $this->match(Lexer::T_IDENTIFIER); $field = $this->lexer->token['value']; + + while ($this->lexer->isNextToken(Lexer::T_DOT)) { + $this->match(Lexer::T_DOT); + $this->match(Lexer::T_IDENTIFIER); + $field .= '.'.$this->lexer->token['value']; + } } // Creating AST node diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php index 89a51a406..a309acdb1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php @@ -101,6 +101,24 @@ class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals('funkytown', $person['address.city']); } } + + /** + * @group dql + */ + public function testDqlOnEmbeddedObjectsField() + { + $person = new DDC93Person('Johannes', new DDC93Address('Moo', '12345', 'Karlsruhe')); + $this->_em->persist($person); + $this->_em->flush($person); + + $dql = "SELECT p FROM " . __NAMESPACE__ ."\\DDC93Person p WHERE p.address.city = :city"; + $loadedPerson = $this->_em->createQuery($dql) + ->setParameter('city', 'Karlsruhe') + ->getSingleResult(); + $this->assertEquals($person, $loadedPerson); + + $this->assertNull($this->_em->createQuery($dql)->setParameter('city', 'asdf')->getOneOrNullResult()); + } } /** @@ -118,6 +136,12 @@ class DDC93Person /** @Embedded(class="DDC93Address") */ public $address; + + public function __construct($name = null, DDC93Address $address = null) + { + $this->name = $name; + $this->address = $address; + } } /** @@ -139,5 +163,12 @@ class DDC93Address * @Column(type="string") */ public $city; + + public function __construct($street = null, $zip = null, $city = null) + { + $this->street = $street; + $this->zip = $zip; + $this->city = $city; + } }