Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/Doctrine/ORM/Query/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1784,8 +1784,16 @@ public function PartialObjectExpression()
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);
Expand Down
44 changes: 44 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,42 @@ public function testDqlOnEmbeddedObjectsField()
$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()
{
Expand All @@ -180,6 +216,14 @@ public function testDqlWithNonExistentEmbeddableField()
$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()
{
Expand Down