diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 0d2fa8aa9..550cc5a3a 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1084,17 +1084,23 @@ public function __construct() $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'JoinTable(' . implode(', ', $joinTable) . ','; $lines[] = $this->spaces . ' * joinColumns={'; + $joinColumnsLines = array(); + foreach ($associationMapping['joinTable']['joinColumns'] as $joinColumn) { - $lines[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn); + $joinColumnsLines[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn); } + $lines[] = implode(",". PHP_EOL, $joinColumnsLines); $lines[] = $this->spaces . ' * },'; $lines[] = $this->spaces . ' * inverseJoinColumns={'; + $inverseJoinColumnsLines = array(); + foreach ($associationMapping['joinTable']['inverseJoinColumns'] as $joinColumn) { - $lines[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn); + $inverseJoinColumnsLines[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn); } + $lines[] = implode(",". PHP_EOL, $inverseJoinColumnsLines); $lines[] = $this->spaces . ' * }'; $lines[] = $this->spaces . ' * )'; } diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index 96d078c02..ca8c9de55 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -278,6 +278,50 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $this->assertContains('@SequenceGenerator(sequenceName="DDC1784_ID_SEQ", allocationSize=1, initialValue=2)', $docComment); } + /** + * @group DDC-2079 + */ + public function testGenerateEntityWithMultipleInverseJoinColumns() + { + $metadata = new ClassMetadataInfo($this->_namespace . '\DDC2079Entity'); + $metadata->namespace = $this->_namespace; + $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); + $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE); + $metadata->mapManyToMany(array( + 'fieldName' => 'centroCustos', + 'targetEntity' => 'DDC2079CentroCusto', + 'joinTable' => array( + 'name' => 'unidade_centro_custo', + 'joinColumns' => array( + array('name' => 'idorcamento', 'referencedColumnName' => 'idorcamento'), + array('name' => 'idunidade', 'referencedColumnName' => 'idunidade') + ), + 'inverseJoinColumns' => array( + array('name' => 'idcentrocusto', 'referencedColumnName' => 'idcentrocusto'), + array('name' => 'idpais', 'referencedColumnName' => 'idpais'), + ), + ), + )); + $this->_generator->writeEntityClass($metadata, $this->_tmpDir); + + $filename = $this->_tmpDir . DIRECTORY_SEPARATOR + . $this->_namespace . DIRECTORY_SEPARATOR . 'DDC2079Entity.php'; + + $this->assertFileExists($filename); + require_once $filename; + + $propertu = new \ReflectionProperty($metadata->name, 'centroCustos'); + $docComment = $propertu->getDocComment(); + + //joinColumns + $this->assertContains('@JoinColumn(name="idorcamento", referencedColumnName="idorcamento"),', $docComment); + $this->assertContains('@JoinColumn(name="idunidade", referencedColumnName="idunidade")', $docComment); + //inverseJoinColumns + $this->assertContains('@JoinColumn(name="idcentrocusto", referencedColumnName="idcentrocusto"),', $docComment); + $this->assertContains('@JoinColumn(name="idpais", referencedColumnName="idpais")', $docComment); + + } + /** * @dataProvider getEntityTypeAliasDataProvider *