diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 8a444d9ae..6a2931fe6 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -895,7 +895,7 @@ class ClassMetadataInfo implements ClassMetadata foreach ($this->fieldMappings as $field => $mapping) { if (isset($mapping['declaredField'])) { - $this->reflFields[$field] = new ReflectionProxy( + $this->reflFields[$field] = new ReflectionEmbeddedProperty( $reflService->getAccessibleProperty($this->name, $mapping['declaredField']), $reflService->getAccessibleProperty($this->embeddedClasses[$mapping['declaredField']], $mapping['originalField']), $this->embeddedClasses[$mapping['declaredField']] diff --git a/lib/Doctrine/ORM/Mapping/ReflectionProxy.php b/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php similarity index 96% rename from lib/Doctrine/ORM/Mapping/ReflectionProxy.php rename to lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php index 9d391d9a8..b68d7d818 100644 --- a/lib/Doctrine/ORM/Mapping/ReflectionProxy.php +++ b/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php @@ -25,8 +25,10 @@ namespace Doctrine\ORM\Mapping; * * This way value objects "just work" without UnitOfWork, Persisters or Hydrators * needing any changes. + * + * TODO: Move this class into Common\Reflection */ -class ReflectionProxy +class ReflectionEmbeddedProperty { private $parentProperty; private $childProperty; diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php index d1f81189c..89a51a406 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php @@ -11,10 +11,13 @@ class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase { parent::setUp(); - $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Person'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Address'), - )); + try { + $this->_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Person'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Address'), + )); + } catch(\Exception $e) { + } } public function testCRUD() @@ -61,6 +64,43 @@ class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertNull($this->_em->find(DDC93Person::CLASSNAME, $personId)); } + + public function testLoadDql() + { + for ($i = 0; $i < 3; $i++) { + $person = new DDC93Person(); + $person->name = "Donkey Kong$i"; + $person->address = new DDC93Address(); + $person->address->street = "Tree"; + $person->address->zip = "12345"; + $person->address->city = "funkytown"; + + $this->_em->persist($person); + } + + $this->_em->flush(); + $this->_em->clear(); + + $dql = "SELECT p FROM " . __NAMESPACE__ . "\DDC93Person p"; + $persons = $this->_em->createQuery($dql)->getResult(); + + $this->assertCount(3, $persons); + foreach ($persons as $person) { + $this->assertInstanceOf(DDC93Address::CLASSNAME, $person->address); + $this->assertEquals('Tree', $person->address->street); + $this->assertEquals('12345', $person->address->zip); + $this->assertEquals('funkytown', $person->address->city); + } + + $dql = "SELECT p FROM " . __NAMESPACE__ . "\DDC93Person p"; + $persons = $this->_em->createQuery($dql)->getArrayResult(); + + foreach ($persons as $person) { + $this->assertEquals('Tree', $person['address.street']); + $this->assertEquals('12345', $person['address.zip']); + $this->assertEquals('funkytown', $person['address.city']); + } + } } /**