1
0
mirror of synced 2024-12-05 03:06:05 +03:00

Merge pull request #1343 from karlrixon/master

Support embeddables in partial object query expression [DDC-3621]
This commit is contained in:
Marco Pivetta 2015-03-23 23:43:36 +00:00
commit 70c8591bbe
2 changed files with 54 additions and 2 deletions

View File

@ -1784,8 +1784,16 @@ class Parser
while ($this->lexer->isNextToken(Lexer::T_COMMA)) {
$this->match(Lexer::T_COMMA);
$this->match(Lexer::T_IDENTIFIER);
$partialFieldSet[] = $this->lexer->token['value'];
$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'];
}
$partialFieldSet[] = $field;
}
$this->match(Lexer::T_CLOSE_CURLY_BRACE);

View File

@ -172,6 +172,42 @@ class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->clear();
$this->assertNull($this->_em->find(__NAMESPACE__.'\\DDC93Person', $person->id));
}
public function testPartialDqlOnEmbeddedObjectsField()
{
$person = new DDC93Person('Karl', new DDC93Address('Foo', '12345', 'Gosport', new DDC93Country('England')));
$this->_em->persist($person);
$this->_em->flush($person);
$this->_em->clear();
// Prove that the entity was persisted correctly.
$dql = "SELECT p FROM " . __NAMESPACE__ ."\\DDC93Person p WHERE p.name = :name";
$person = $this->_em->createQuery($dql)
->setParameter('name', 'Karl')
->getSingleResult();
$this->assertEquals('Gosport', $person->address->city);
$this->assertEquals('Foo', $person->address->street);
$this->assertEquals('12345', $person->address->zip);
$this->assertEquals('England', $person->address->country->name);
// Clear the EM and prove that the embeddable can be the subject of a partial query.
$this->_em->clear();
$dql = "SELECT PARTIAL p.{id,address.city} FROM " . __NAMESPACE__ ."\\DDC93Person p WHERE p.name = :name";
$person = $this->_em->createQuery($dql)
->setParameter('name', 'Karl')
->getSingleResult();
// Selected field must be equal, all other fields must be null.
$this->assertEquals('Gosport', $person->address->city);
$this->assertNull($person->address->street);
$this->assertNull($person->address->zip);
$this->assertNull($person->address->country);
$this->assertNull($person->name);
}
public function testDqlWithNonExistentEmbeddableField()
{
@ -180,6 +216,14 @@ class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->createQuery("SELECT p FROM " . __NAMESPACE__ . "\\DDC93Person p WHERE p.address.asdfasdf IS NULL")
->execute();
}
public function testPartialDqlWithNonExistentEmbeddableField()
{
$this->setExpectedException('Doctrine\ORM\Query\QueryException', "no mapped field named 'address.asdfasdf'");
$this->_em->createQuery("SELECT PARTIAL p.{id,address.asdfasdf} FROM " . __NAMESPACE__ . "\\DDC93Person p")
->execute();
}
public function testEmbeddableWithInheritance()
{