1
0
mirror of synced 2025-01-18 14:31:40 +03:00

[DDC-642] Fixes issue with exporters not including inversedBy functionality

This commit is contained in:
Jonathan H. Wage 2010-06-16 11:47:22 -04:00
parent e6f465ec80
commit 20c1ff3146
9 changed files with 33 additions and 9 deletions

View File

@ -698,6 +698,10 @@ public function <methodName>()
$typeOptions[] = 'targetEntity="' . $associationMapping->targetEntityName . '"';
}
if (isset($associationMapping->inversedBy)) {
$typeOptions[] = 'inversedBy="' . $associationMapping->inversedBy . '"';
}
if (isset($associationMapping->mappedBy)) {
$typeOptions[] = 'mappedBy="' . $associationMapping->mappedBy . '"';
}

View File

@ -113,6 +113,7 @@ class PhpExporter extends AbstractExporter
$method = 'mapOneToOne';
$oneToOneMappingArray = array(
'mappedBy' => $associationMapping->mappedBy,
'inversedBy' => $associationMapping->inversedBy,
'joinColumns' => $associationMapping->joinColumns,
'orphanRemoval' => $associationMapping->orphanRemoval,
);

View File

@ -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);
}

View File

@ -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
);

View File

@ -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();

View File

@ -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;

View File

@ -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',

View File

@ -20,7 +20,7 @@
<field name="name" column="name" type="string" length="50" nullable="true" unique="true" />
<field name="email" column="user_email" type="string" column-definition="CHAR(32) NOT NULL" />
<one-to-one field="address" target-entity="Doctrine\Tests\ORM\Tools\Export\Address">
<one-to-one field="address" target-entity="Doctrine\Tests\ORM\Tools\Export\Address" inversed-by="user">
<cascade><cascade-remove /></cascade>
<join-column name="address_id" referenced-column-name="id" on-delete="CASCADE" on-update="CASCADE"/>
</one-to-one>

View File

@ -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