Skip to content

Commit

Permalink
adds support for selecting based on embedded fields
Browse files Browse the repository at this point in the history
  • Loading branch information
schmittjoh committed Nov 1, 2013
1 parent 38b041d commit c67ac8a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/Doctrine/ORM/Query/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ public function JoinAssociationPathExpression()
* Parses an arbitrary path expression and defers semantical validation
* based on expected types.
*
* PathExpression ::= IdentificationVariable "." identifier
* PathExpression ::= IdentificationVariable "." identifier [ ("." identifier)* ]
*
* @param integer $expectedTypes
*
Expand All @@ -1065,6 +1065,12 @@ public function PathExpression($expectedTypes)
$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
Expand Down
31 changes: 31 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ public function testLoadDql()
$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());
}
}

/**
Expand All @@ -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;
}
}

/**
Expand All @@ -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;
}
}

0 comments on commit c67ac8a

Please sign in to comment.