1
0
mirror of synced 2025-02-20 06:03:15 +03:00

adds support for selecting based on embedded fields

This commit is contained in:
Johannes M. Schmitt 2013-11-01 20:38:19 +01:00
parent 38b041d909
commit c67ac8a11b
2 changed files with 38 additions and 1 deletions

View File

@ -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

View File

@ -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;
}
}