From e3b8ce7737ecd18295db760c4dd1e55037580df4 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Thu, 9 May 2013 10:55:12 +0200 Subject: [PATCH] [DDC-2423] Fixed bug with EntityGenerator not generating fetch="" attribute in association annotations. --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 9 +++++++++ tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php | 3 +++ 2 files changed, 12 insertions(+) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 98a65fb98..5a55f0fc9 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1274,6 +1274,15 @@ public function __construct() $typeOptions[] = 'orphanRemoval=' . ($associationMapping['orphanRemoval'] ? 'true' : 'false'); } + if (isset($associationMapping['fetch']) && $associationMapping['fetch'] !== ClassMetadataInfo::FETCH_LAZY) { + $fetchMap = array( + ClassMetadataInfo::FETCH_EXTRA_LAZY => 'EXTRA_LAZY', + ClassMetadataInfo::FETCH_EAGER => 'EAGER', + ); + + $typeOptions[] = 'fetch="' . $fetchMap[$associationMapping['fetch']] . '"'; + } + $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . '' . $type . '(' . implode(', ', $typeOptions) . ')'; if (isset($associationMapping['joinColumns']) && $associationMapping['joinColumns']) { diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index a55b603d5..d8dfa1b56 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -64,6 +64,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $metadata->mapManyToMany(array( 'fieldName' => 'comments', 'targetEntity' => 'Doctrine\Tests\ORM\Tools\EntityGeneratorComment', + 'fetch' => ClassMetadataInfo::FETCH_EXTRA_LAZY, 'joinTable' => array( 'name' => 'book_comment', 'joinColumns' => array(array('name' => 'book_id', 'referencedColumnName' => 'id')), @@ -223,6 +224,8 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals($cm->identifier, $metadata->identifier); $this->assertEquals($cm->idGenerator, $metadata->idGenerator); $this->assertEquals($cm->customRepositoryClassName, $metadata->customRepositoryClassName); + + $this->assertEquals(ClassMetadataInfo::FETCH_EXTRA_LAZY, $cm->associationMappings['comments']['fetch']); } public function testLoadPrefixedMetadata()