From 20c1ff3146d3af4a1731761b0e036befc4382482 Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Wed, 16 Jun 2010 11:47:22 -0400 Subject: [PATCH] [DDC-642] Fixes issue with exporters not including inversedBy functionality --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 4 ++++ .../ORM/Tools/Export/Driver/PhpExporter.php | 1 + .../ORM/Tools/Export/Driver/XmlExporter.php | 3 +++ .../ORM/Tools/Export/Driver/YamlExporter.php | 7 +++++-- .../AbstractClassMetadataExporterTest.php | 21 ++++++++++++++----- .../Doctrine.Tests.ORM.Tools.Export.User.php | 2 +- .../Doctrine.Tests.ORM.Tools.Export.User.php | 1 + ...ctrine.Tests.ORM.Tools.Export.User.dcm.xml | 2 +- ...ctrine.Tests.ORM.Tools.Export.User.dcm.yml | 1 + 9 files changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index b8a47c64d..2af25891f 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -698,6 +698,10 @@ public function () $typeOptions[] = 'targetEntity="' . $associationMapping->targetEntityName . '"'; } + if (isset($associationMapping->inversedBy)) { + $typeOptions[] = 'inversedBy="' . $associationMapping->inversedBy . '"'; + } + if (isset($associationMapping->mappedBy)) { $typeOptions[] = 'mappedBy="' . $associationMapping->mappedBy . '"'; } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php index 201d1072d..831c28f4a 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php @@ -113,6 +113,7 @@ class PhpExporter extends AbstractExporter $method = 'mapOneToOne'; $oneToOneMappingArray = array( 'mappedBy' => $associationMapping->mappedBy, + 'inversedBy' => $associationMapping->inversedBy, 'joinColumns' => $associationMapping->joinColumns, 'orphanRemoval' => $associationMapping->orphanRemoval, ); diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 0498cc08a..63f28ffc9 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -196,6 +196,9 @@ class XmlExporter extends AbstractExporter if (isset($associationMapping->mappedBy)) { $associationMappingXml->addAttribute('mapped-by', $associationMapping->mappedBy); } + if (isset($associationMapping->inversedBy)) { + $associationMappingXml->addAttribute('inversed-by', $associationMapping->inversedBy); + } if (isset($associationMapping->orphanRemoval)) { $associationMappingXml->addAttribute('orphan-removal', $associationMapping->orphanRemoval); } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index 0eb749ec6..13094a1d9 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -168,6 +168,7 @@ class YamlExporter extends AbstractExporter } $oneToOneMappingArray = array( 'mappedBy' => $associationMapping->mappedBy, + 'inversedBy' => $associationMapping->inversedBy, 'joinColumns' => $newJoinColumns, 'orphanRemoval' => $associationMapping->orphanRemoval, ); @@ -177,6 +178,7 @@ class YamlExporter extends AbstractExporter } else if ($associationMapping instanceof OneToManyMapping) { $oneToManyMappingArray = array( 'mappedBy' => $associationMapping->mappedBy, + 'inversedBy' => $associationMapping->inversedBy, 'orphanRemoval' => $associationMapping->orphanRemoval, 'orderBy' => $associationMapping->orderBy ); @@ -185,8 +187,9 @@ class YamlExporter extends AbstractExporter $array['oneToMany'][$name] = $associationMappingArray; } else if ($associationMapping instanceof ManyToManyMapping) { $manyToManyMappingArray = array( - 'mappedBy' => $associationMapping->mappedBy, - 'joinTable' => $associationMapping->joinTable, + 'mappedBy' => $associationMapping->mappedBy, + 'inversedBy' => $associationMapping->inversedBy, + 'joinTable' => $associationMapping->joinTable, 'orderBy' => $associationMapping->orderBy ); diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index 9a6a2b9ff..0fa781285 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -102,7 +102,9 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest $cmf = $this->_createClassMetadataFactory($em, $type); $metadata = $cmf->getAllMetadata(); - $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\User', $metadata[0]->name); + $metadata[0]->name = 'Doctrine\Tests\ORM\Tools\Export\ExportedUser'; + + $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\ExportedUser', $metadata[0]->name); $type = $this->_getType(); $cme = new ClassMetadataExporter(); @@ -117,9 +119,9 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest $exporter->export(); if ($type == 'annotation') { - $this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/'.str_replace('\\', '/', 'Doctrine\Tests\ORM\Tools\Export\User').$this->_extension)); + $this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/'.str_replace('\\', '/', 'Doctrine\Tests\ORM\Tools\Export\ExportedUser').$this->_extension)); } else { - $this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/Doctrine.Tests.ORM.Tools.Export.User'.$this->_extension)); + $this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/Doctrine.Tests.ORM.Tools.Export.ExportedUser'.$this->_extension)); } } @@ -130,14 +132,14 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest { $type = $this->_getType(); - $metadataDriver = $this->_createMetadataDriver($type, __DIR__ . '/' . $type); + $metadataDriver = $this->_createMetadataDriver($type, __DIR__ . '/export/' . $type); $em = $this->_createEntityManager($metadataDriver); $cmf = $this->_createClassMetadataFactory($em, $type); $metadata = $cmf->getAllMetadata(); $class = current($metadata); - $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\User', $class->name); + $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\ExportedUser', $class->name); return $class; } @@ -304,6 +306,15 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest return $class; } + /** + * @depends testCascadeIsExported + * @param ClassMetadataInfo $class + */ + public function testInversedByIsExported($class) + { + $this->assertEquals('user', $class->associationMappings['address']->inversedBy); + } + public function __destruct() { $type = $this->_getType(); diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php b/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php index 25f6fdd7b..e71da460e 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php @@ -23,7 +23,7 @@ class User public $email; /** - * @OneToOne(targetEntity="Doctrine\Tests\ORM\Tools\Export\Address", cascade={"remove"}) + * @OneToOne(targetEntity="Doctrine\Tests\ORM\Tools\Export\Address", cascade={"remove"}, inversedBy="user") * @JoinColumn(name="address_id", onDelete="CASCADE", onUpdate="CASCADE") */ public $address; diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php b/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php index 5b1e328e1..1a3824543 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php @@ -34,6 +34,7 @@ $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); $metadata->mapOneToOne(array( 'fieldName' => 'address', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Address', + 'inversedBy' => 'user', 'cascade' => array( 0 => 'remove', diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml b/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml index e8444e738..11bb6ac95 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml @@ -20,7 +20,7 @@ - + diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml b/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml index d60f41026..2b3048fba 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml @@ -25,6 +25,7 @@ Doctrine\Tests\ORM\Tools\Export\User: onDelete: CASCADE onUpdate: CASCADE cascade: [ remove ] + inversedBy: user oneToMany: phonenumbers: targetEntity: Doctrine\Tests\ORM\Tools\Export\Phonenumber