1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

[DDC-1799] Fix bug in YamlExporter using OneToOne instead of ManyToOne

This commit is contained in:
Benjamin Eberlei 2012-05-27 09:57:46 +02:00
parent 0868ec1c19
commit 548c997f7b
6 changed files with 46 additions and 18 deletions

View file

@ -171,7 +171,13 @@ class YamlExporter extends AbstractExporter
); );
$associationMappingArray = array_merge($associationMappingArray, $oneToOneMappingArray); $associationMappingArray = array_merge($associationMappingArray, $oneToOneMappingArray);
$array['oneToOne'][$name] = $associationMappingArray;
if ($associationMapping['type'] & ClassMetadataInfo::ONE_TO_ONE) {
$array['oneToOne'][$name] = $associationMappingArray;
} else {
$array['manyToOne'][$name] = $associationMappingArray;
}
} else if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_MANY) { } else if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_MANY) {
$oneToManyMappingArray = array( $oneToManyMappingArray = array(
'mappedBy' => $associationMapping['mappedBy'], 'mappedBy' => $associationMapping['mappedBy'],

View file

@ -68,10 +68,10 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
protected function _createMetadataDriver($type, $path) protected function _createMetadataDriver($type, $path)
{ {
$mappingDriver = array( $mappingDriver = array(
'php' => 'PHPDriver', 'php' => 'PHPDriver',
'annotation' => 'AnnotationDriver', 'annotation' => 'AnnotationDriver',
'xml' => 'XmlDriver', 'xml' => 'XmlDriver',
'yaml' => 'YamlDriver', 'yaml' => 'YamlDriver',
); );
$this->assertArrayHasKey($type, $mappingDriver, "There is no metadata driver for the type '" . $type . "'."); $this->assertArrayHasKey($type, $mappingDriver, "There is no metadata driver for the type '" . $type . "'.");
$driverName = $mappingDriver[$type]; $driverName = $mappingDriver[$type];
@ -190,7 +190,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
* @depends testIdentifierIsExported * @depends testIdentifierIsExported
* @param ClassMetadataInfo $class * @param ClassMetadataInfo $class
*/ */
public function testFieldsAreExpored($class) public function testFieldsAreExported($class)
{ {
$this->assertTrue(isset($class->fieldMappings['id']['id']) && $class->fieldMappings['id']['id'] === true); $this->assertTrue(isset($class->fieldMappings['id']['id']) && $class->fieldMappings['id']['id'] === true);
$this->assertEquals('id', $class->fieldMappings['id']['fieldName']); $this->assertEquals('id', $class->fieldMappings['id']['fieldName']);
@ -211,13 +211,12 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
} }
/** /**
* @depends testFieldsAreExpored * @depends testFieldsAreExported
* @param ClassMetadataInfo $class * @param ClassMetadataInfo $class
*/ */
public function testOneToOneAssociationsAreExported($class) public function testOneToOneAssociationsAreExported($class)
{ {
$this->assertTrue(isset($class->associationMappings['address'])); $this->assertTrue(isset($class->associationMappings['address']));
//$this->assertInstanceOf('Doctrine\ORM\Mapping\OneToOneMapping', $class->associationMappings['address']);
$this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Address', $class->associationMappings['address']['targetEntity']); $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Address', $class->associationMappings['address']['targetEntity']);
$this->assertEquals('address_id', $class->associationMappings['address']['joinColumns'][0]['name']); $this->assertEquals('address_id', $class->associationMappings['address']['joinColumns'][0]['name']);
$this->assertEquals('id', $class->associationMappings['address']['joinColumns'][0]['referencedColumnName']); $this->assertEquals('id', $class->associationMappings['address']['joinColumns'][0]['referencedColumnName']);
@ -233,6 +232,15 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
return $class; return $class;
} }
/**
* @depends testFieldsAreExported
*/
public function testManyToOneAssociationsAreExported($class)
{
$this->assertTrue(isset($class->associationMappings['mainGroup']));
$this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Group', $class->associationMappings['mainGroup']['targetEntity']);
}
/** /**
* @depends testOneToOneAssociationsAreExported * @depends testOneToOneAssociationsAreExported
* @param ClassMetadataInfo $class * @param ClassMetadataInfo $class

View file

@ -28,6 +28,11 @@ class User
*/ */
public $address; public $address;
/**
* @ManyToOne(targetEntity="Doctrine\Tests\ORM\Tools\Export\Group")
*/
public $mainGroup;
/** /**
* *
* @OneToMany(targetEntity="Doctrine\Tests\ORM\Tools\Export\Phonenumber", mappedBy="user", cascade={"persist", "merge"}, orphanRemoval=true) * @OneToMany(targetEntity="Doctrine\Tests\ORM\Tools\Export\Phonenumber", mappedBy="user", cascade={"persist", "merge"}, orphanRemoval=true)
@ -65,4 +70,4 @@ class User
public function doStuffOnPostPersist() public function doStuffOnPostPersist()
{ {
} }
} }

View file

@ -31,6 +31,10 @@ $metadata->mapField(array(
'columnDefinition' => 'CHAR(32) NOT NULL', 'columnDefinition' => 'CHAR(32) NOT NULL',
)); ));
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
$metadata->mapManyToOne(array(
'fieldName' => 'mainGroup',
'targetEntity' => 'Doctrine\\Tests\\ORM\Tools\\Export\\Group',
));
$metadata->mapOneToOne(array( $metadata->mapOneToOne(array(
'fieldName' => 'address', 'fieldName' => 'address',
'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Address', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Address',
@ -102,4 +106,4 @@ $metadata->mapManyToMany(array(
), ),
), ),
'orderBy' => NULL, 'orderBy' => NULL,
)); ));

View file

@ -4,9 +4,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Doctrine\Tests\ORM\Tools\Export\User" table="cms_users"> <entity name="Doctrine\Tests\ORM\Tools\Export\User" table="cms_users">
<lifecycle-callbacks> <lifecycle-callbacks>
<lifecycle-callback type="prePersist" method="doStuffOnPrePersist"/> <lifecycle-callback type="prePersist" method="doStuffOnPrePersist"/>
<lifecycle-callback type="prePersist" method="doOtherStuffOnPrePersistToo"/> <lifecycle-callback type="prePersist" method="doOtherStuffOnPrePersistToo"/>
@ -16,15 +16,17 @@
<id name="id" type="integer" column="id"> <id name="id" type="integer" column="id">
<generator strategy="AUTO"/> <generator strategy="AUTO"/>
</id> </id>
<field name="name" column="name" type="string" length="50" nullable="true" unique="true" /> <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" /> <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" inversed-by="user" orphan-removal="true"> <one-to-one field="address" target-entity="Doctrine\Tests\ORM\Tools\Export\Address" inversed-by="user" orphan-removal="true">
<cascade><cascade-persist /></cascade> <cascade><cascade-persist /></cascade>
<join-column name="address_id" referenced-column-name="id" on-delete="CASCADE" on-update="CASCADE"/> <join-column name="address_id" referenced-column-name="id" on-delete="CASCADE" on-update="CASCADE"/>
</one-to-one> </one-to-one>
<many-to-one field="mainGroup" target-entity="Doctrine\Tests\ORM\Tools\Export\Group" />
<one-to-many field="phonenumbers" target-entity="Doctrine\Tests\ORM\Tools\Export\Phonenumber" mapped-by="user" orphan-removal="true"> <one-to-many field="phonenumbers" target-entity="Doctrine\Tests\ORM\Tools\Export\Phonenumber" mapped-by="user" orphan-removal="true">
<cascade> <cascade>
<cascade-persist/> <cascade-persist/>
@ -34,7 +36,7 @@
<order-by-field name="number" direction="ASC" /> <order-by-field name="number" direction="ASC" />
</order-by> </order-by>
</one-to-many> </one-to-many>
<one-to-many field="interests" target-entity="Doctrine\Tests\ORM\Tools\Export\Interests" mapped-by="user" orphan-removal="true"> <one-to-many field="interests" target-entity="Doctrine\Tests\ORM\Tools\Export\Interests" mapped-by="user" orphan-removal="true">
<cascade> <cascade>
<cascade-refresh/> <cascade-refresh/>
@ -44,7 +46,7 @@
<cascade-remove/> <cascade-remove/>
</cascade> </cascade>
</one-to-many> </one-to-many>
<many-to-many field="groups" target-entity="Doctrine\Tests\ORM\Tools\Export\Group"> <many-to-many field="groups" target-entity="Doctrine\Tests\ORM\Tools\Export\Group">
<cascade> <cascade>
<cascade-all/> <cascade-all/>
@ -58,7 +60,7 @@
</inverse-join-columns> </inverse-join-columns>
</join-table> </join-table>
</many-to-many> </many-to-many>
</entity> </entity>
</doctrine-mapping> </doctrine-mapping>

View file

@ -26,6 +26,9 @@ Doctrine\Tests\ORM\Tools\Export\User:
cascade: [ persist ] cascade: [ persist ]
inversedBy: user inversedBy: user
orphanRemoval: true orphanRemoval: true
manyToOne:
mainGroup:
targetEntity: Doctrine\Tests\ORM\Tools\Export\Group
oneToMany: oneToMany:
phonenumbers: phonenumbers:
targetEntity: Doctrine\Tests\ORM\Tools\Export\Phonenumber targetEntity: Doctrine\Tests\ORM\Tools\Export\Phonenumber
@ -57,4 +60,4 @@ Doctrine\Tests\ORM\Tools\Export\User:
- all - all
lifecycleCallbacks: lifecycleCallbacks:
prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersistToo ] prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersistToo ]
postPersist: [ doStuffOnPostPersist ] postPersist: [ doStuffOnPostPersist ]