1
0
mirror of synced 2024-12-14 15:16:04 +03:00

Merge branch 'DDC-1799'

This commit is contained in:
Benjamin Eberlei 2012-05-27 09:58:01 +02:00
commit 9ae5b8f442
6 changed files with 46 additions and 18 deletions

View File

@ -171,7 +171,13 @@ class YamlExporter extends AbstractExporter
);
$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) {
$oneToManyMappingArray = array(
'mappedBy' => $associationMapping['mappedBy'],

View File

@ -68,10 +68,10 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
protected function _createMetadataDriver($type, $path)
{
$mappingDriver = array(
'php' => 'PHPDriver',
'php' => 'PHPDriver',
'annotation' => 'AnnotationDriver',
'xml' => 'XmlDriver',
'yaml' => 'YamlDriver',
'xml' => 'XmlDriver',
'yaml' => 'YamlDriver',
);
$this->assertArrayHasKey($type, $mappingDriver, "There is no metadata driver for the type '" . $type . "'.");
$driverName = $mappingDriver[$type];
@ -190,7 +190,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
* @depends testIdentifierIsExported
* @param ClassMetadataInfo $class
*/
public function testFieldsAreExpored($class)
public function testFieldsAreExported($class)
{
$this->assertTrue(isset($class->fieldMappings['id']['id']) && $class->fieldMappings['id']['id'] === true);
$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
*/
public function testOneToOneAssociationsAreExported($class)
{
$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('address_id', $class->associationMappings['address']['joinColumns'][0]['name']);
$this->assertEquals('id', $class->associationMappings['address']['joinColumns'][0]['referencedColumnName']);
@ -233,6 +232,15 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
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
* @param ClassMetadataInfo $class

View File

@ -28,6 +28,11 @@ class User
*/
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)

View File

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

View File

@ -25,6 +25,8 @@
<join-column name="address_id" referenced-column-name="id" on-delete="CASCADE" on-update="CASCADE"/>
</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">
<cascade>
<cascade-persist/>

View File

@ -26,6 +26,9 @@ Doctrine\Tests\ORM\Tools\Export\User:
cascade: [ persist ]
inversedBy: user
orphanRemoval: true
manyToOne:
mainGroup:
targetEntity: Doctrine\Tests\ORM\Tools\Export\Group
oneToMany:
phonenumbers:
targetEntity: Doctrine\Tests\ORM\Tools\Export\Phonenumber