1
0
mirror of synced 2025-01-09 10:37:09 +03:00

Exporter support for association fetch modes

This commit is contained in:
Menno Holtkamp 2014-03-26 01:00:17 +01:00
parent 048c56bdb0
commit 798075931a
8 changed files with 45 additions and 5 deletions

View File

@ -200,6 +200,25 @@ abstract class AbstractExporter
} }
} }
/**
* @param int $mode
*
* @return string
*/
protected function _getFetchModeString($mode)
{
switch ($mode) {
case ClassMetadataInfo::FETCH_EAGER:
return 'EAGER';
case ClassMetadataInfo::FETCH_EXTRA_LAZY:
return 'EXTRA_LAZY';
case ClassMetadataInfo::FETCH_LAZY:
return 'LAZY';
}
}
/** /**
* @param int $policy * @param int $policy
* *

View File

@ -108,6 +108,10 @@ class PhpExporter extends AbstractExporter
'cascade' => $cascade, 'cascade' => $cascade,
); );
if(isset($associationMapping['fetch'])){
$associationMappingArray['fetch'] = $associationMapping['fetch'];
}
if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) { if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) {
$method = 'mapOneToOne'; $method = 'mapOneToOne';
$oneToOneMappingArray = array( $oneToOneMappingArray = array(

View File

@ -260,6 +260,10 @@ class XmlExporter extends AbstractExporter
if (isset($associationMapping['orphanRemoval']) && $associationMapping['orphanRemoval'] !== false) { if (isset($associationMapping['orphanRemoval']) && $associationMapping['orphanRemoval'] !== false) {
$associationMappingXml->addAttribute('orphan-removal', 'true'); $associationMappingXml->addAttribute('orphan-removal', 'true');
} }
if (isset($associationMapping['fetch'])) {
$associationMappingXml->addAttribute('fetch', $this->_getFetchModeString($associationMapping['fetch']));
}
$cascade = array(); $cascade = array();
if ($associationMapping['isCascadeRemove']) { if ($associationMapping['isCascadeRemove']) {

View File

@ -150,6 +150,10 @@ class YamlExporter extends AbstractExporter
'cascade' => $cascade, 'cascade' => $cascade,
); );
if(isset($associationMapping['fetch'])){
$associationMappingArray['fetch'] = $this->_getFetchModeString($associationMapping['fetch']);
}
if (isset($mapping['id']) && $mapping['id'] === true) { if (isset($mapping['id']) && $mapping['id'] === true) {
$array['id'][$name]['associationKey'] = true; $array['id'][$name]['associationKey'] = true;
} }

View File

@ -226,7 +226,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
$this->assertEquals(1, count($nodes)); $this->assertEquals(1, count($nodes));
} }
else { else {
$this->markTestSkipped('Test available only for '.$type.' driver'); $this->markTestSkipped('Test not available for '.$type.' driver');
} }
} }
@ -248,6 +248,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
$this->assertFalse($class->associationMappings['address']['isCascadeMerge']); $this->assertFalse($class->associationMappings['address']['isCascadeMerge']);
$this->assertFalse($class->associationMappings['address']['isCascadeDetach']); $this->assertFalse($class->associationMappings['address']['isCascadeDetach']);
$this->assertTrue($class->associationMappings['address']['orphanRemoval']); $this->assertTrue($class->associationMappings['address']['orphanRemoval']);
$this->assertEquals(ClassMetadataInfo::FETCH_EAGER, $class->associationMappings['address']['fetch']);
return $class; return $class;
} }
@ -279,6 +280,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
$this->assertTrue($class->associationMappings['phonenumbers']['isCascadeMerge']); $this->assertTrue($class->associationMappings['phonenumbers']['isCascadeMerge']);
$this->assertFalse($class->associationMappings['phonenumbers']['isCascadeDetach']); $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeDetach']);
$this->assertTrue($class->associationMappings['phonenumbers']['orphanRemoval']); $this->assertTrue($class->associationMappings['phonenumbers']['orphanRemoval']);
$this->assertEquals(ClassMetadataInfo::FETCH_LAZY, $class->associationMappings['phonenumbers']['fetch']);
return $class; return $class;
} }
@ -306,6 +308,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
$this->assertTrue($class->associationMappings['groups']['isCascadeRefresh']); $this->assertTrue($class->associationMappings['groups']['isCascadeRefresh']);
$this->assertTrue($class->associationMappings['groups']['isCascadeMerge']); $this->assertTrue($class->associationMappings['groups']['isCascadeMerge']);
$this->assertTrue($class->associationMappings['groups']['isCascadeDetach']); $this->assertTrue($class->associationMappings['groups']['isCascadeDetach']);
$this->assertEquals(ClassMetadataInfo::FETCH_EXTRA_LAZY, $class->associationMappings['groups']['fetch']);
return $class; return $class;
} }
@ -376,7 +379,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
$this->assertEquals('all', $value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'][0]); $this->assertEquals('all', $value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'][0]);
} else { } else {
$this->markTestSkipped('Test available only for '.$type.' driver'); $this->markTestSkipped('Test not available for '.$type.' driver');
} }
} }
public function __destruct() public function __destruct()

View File

@ -54,6 +54,7 @@ $metadata->mapOneToOne(array(
), ),
), ),
'orphanRemoval' => true, 'orphanRemoval' => true,
'fetch' => ClassMetadataInfo::FETCH_EAGER,
)); ));
$metadata->mapOneToMany(array( $metadata->mapOneToMany(array(
'fieldName' => 'phonenumbers', 'fieldName' => 'phonenumbers',
@ -65,6 +66,7 @@ $metadata->mapOneToMany(array(
), ),
'mappedBy' => 'user', 'mappedBy' => 'user',
'orphanRemoval' => true, 'orphanRemoval' => true,
'fetch' => ClassMetadataInfo::FETCH_LAZY,
'orderBy' => 'orderBy' =>
array( array(
'number' => 'ASC', 'number' => 'ASC',
@ -73,6 +75,7 @@ $metadata->mapOneToMany(array(
$metadata->mapManyToMany(array( $metadata->mapManyToMany(array(
'fieldName' => 'groups', 'fieldName' => 'groups',
'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Group', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Group',
'fetch' => ClassMetadataInfo::FETCH_EXTRA_LAZY,
'cascade' => 'cascade' =>
array( array(
0 => 'remove', 0 => 'remove',

View File

@ -20,14 +20,14 @@
<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" fetch="EAGER">
<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" /> <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" fetch="LAZY">
<cascade> <cascade>
<cascade-persist/> <cascade-persist/>
<cascade-merge/> <cascade-merge/>
@ -47,7 +47,7 @@
</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" fetch="EXTRA_LAZY">
<cascade> <cascade>
<cascade-all/> <cascade-all/>
</cascade> </cascade>

View File

@ -26,6 +26,7 @@ Doctrine\Tests\ORM\Tools\Export\User:
cascade: [ persist ] cascade: [ persist ]
inversedBy: user inversedBy: user
orphanRemoval: true orphanRemoval: true
fetch: EAGER
manyToOne: manyToOne:
mainGroup: mainGroup:
targetEntity: Doctrine\Tests\ORM\Tools\Export\Group targetEntity: Doctrine\Tests\ORM\Tools\Export\Group
@ -37,6 +38,7 @@ Doctrine\Tests\ORM\Tools\Export\User:
number: ASC number: ASC
cascade: [ persist, merge ] cascade: [ persist, merge ]
orphanRemoval: true orphanRemoval: true
fetch: LAZY
interests: interests:
targetEntity: Doctrine\Tests\ORM\Tools\Export\Interests targetEntity: Doctrine\Tests\ORM\Tools\Export\Interests
mappedBy: user mappedBy: user
@ -45,6 +47,7 @@ Doctrine\Tests\ORM\Tools\Export\User:
manyToMany: manyToMany:
groups: groups:
targetEntity: Doctrine\Tests\ORM\Tools\Export\Group targetEntity: Doctrine\Tests\ORM\Tools\Export\Group
fetch: EXTRA_LAZY
joinTable: joinTable:
name: cms_users_groups name: cms_users_groups
joinColumns: joinColumns: