adds support for selecting based on embedded fields
This commit is contained in:
parent
38b041d909
commit
c67ac8a11b
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user