Exporter support for association fetch modes
This commit is contained in:
parent
048c56bdb0
commit
798075931a
@ -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
|
||||
*
|
||||
|
@ -108,6 +108,10 @@ class PhpExporter extends AbstractExporter
|
||||
'cascade' => $cascade,
|
||||
);
|
||||
|
||||
if(isset($associationMapping['fetch'])){
|
||||
$associationMappingArray['fetch'] = $associationMapping['fetch'];
|
||||
}
|
||||
|
||||
if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) {
|
||||
$method = 'mapOneToOne';
|
||||
$oneToOneMappingArray = array(
|
||||
|
@ -260,6 +260,10 @@ class XmlExporter extends AbstractExporter
|
||||
if (isset($associationMapping['orphanRemoval']) && $associationMapping['orphanRemoval'] !== false) {
|
||||
$associationMappingXml->addAttribute('orphan-removal', 'true');
|
||||
}
|
||||
|
||||
if (isset($associationMapping['fetch'])) {
|
||||
$associationMappingXml->addAttribute('fetch', $this->_getFetchModeString($associationMapping['fetch']));
|
||||
}
|
||||
|
||||
$cascade = array();
|
||||
if ($associationMapping['isCascadeRemove']) {
|
||||
|
@ -150,6 +150,10 @@ class YamlExporter extends AbstractExporter
|
||||
'cascade' => $cascade,
|
||||
);
|
||||
|
||||
if(isset($associationMapping['fetch'])){
|
||||
$associationMappingArray['fetch'] = $this->_getFetchModeString($associationMapping['fetch']);
|
||||
}
|
||||
|
||||
if (isset($mapping['id']) && $mapping['id'] === true) {
|
||||
$array['id'][$name]['associationKey'] = true;
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
|
||||
$this->assertEquals(1, count($nodes));
|
||||
}
|
||||
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']['isCascadeDetach']);
|
||||
$this->assertTrue($class->associationMappings['address']['orphanRemoval']);
|
||||
$this->assertEquals(ClassMetadataInfo::FETCH_EAGER, $class->associationMappings['address']['fetch']);
|
||||
|
||||
return $class;
|
||||
}
|
||||
@ -279,6 +280,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
|
||||
$this->assertTrue($class->associationMappings['phonenumbers']['isCascadeMerge']);
|
||||
$this->assertFalse($class->associationMappings['phonenumbers']['isCascadeDetach']);
|
||||
$this->assertTrue($class->associationMappings['phonenumbers']['orphanRemoval']);
|
||||
$this->assertEquals(ClassMetadataInfo::FETCH_LAZY, $class->associationMappings['phonenumbers']['fetch']);
|
||||
|
||||
return $class;
|
||||
}
|
||||
@ -306,6 +308,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
|
||||
$this->assertTrue($class->associationMappings['groups']['isCascadeRefresh']);
|
||||
$this->assertTrue($class->associationMappings['groups']['isCascadeMerge']);
|
||||
$this->assertTrue($class->associationMappings['groups']['isCascadeDetach']);
|
||||
$this->assertEquals(ClassMetadataInfo::FETCH_EXTRA_LAZY, $class->associationMappings['groups']['fetch']);
|
||||
|
||||
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]);
|
||||
|
||||
} else {
|
||||
$this->markTestSkipped('Test available only for '.$type.' driver');
|
||||
$this->markTestSkipped('Test not available for '.$type.' driver');
|
||||
}
|
||||
}
|
||||
public function __destruct()
|
||||
|
@ -54,6 +54,7 @@ $metadata->mapOneToOne(array(
|
||||
),
|
||||
),
|
||||
'orphanRemoval' => true,
|
||||
'fetch' => ClassMetadataInfo::FETCH_EAGER,
|
||||
));
|
||||
$metadata->mapOneToMany(array(
|
||||
'fieldName' => 'phonenumbers',
|
||||
@ -65,6 +66,7 @@ $metadata->mapOneToMany(array(
|
||||
),
|
||||
'mappedBy' => 'user',
|
||||
'orphanRemoval' => true,
|
||||
'fetch' => ClassMetadataInfo::FETCH_LAZY,
|
||||
'orderBy' =>
|
||||
array(
|
||||
'number' => 'ASC',
|
||||
@ -73,6 +75,7 @@ $metadata->mapOneToMany(array(
|
||||
$metadata->mapManyToMany(array(
|
||||
'fieldName' => 'groups',
|
||||
'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Group',
|
||||
'fetch' => ClassMetadataInfo::FETCH_EXTRA_LAZY,
|
||||
'cascade' =>
|
||||
array(
|
||||
0 => 'remove',
|
||||
|
@ -20,14 +20,14 @@
|
||||
<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" 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>
|
||||
<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">
|
||||
<one-to-many field="phonenumbers" target-entity="Doctrine\Tests\ORM\Tools\Export\Phonenumber" mapped-by="user" orphan-removal="true" fetch="LAZY">
|
||||
<cascade>
|
||||
<cascade-persist/>
|
||||
<cascade-merge/>
|
||||
@ -47,7 +47,7 @@
|
||||
</cascade>
|
||||
</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-all/>
|
||||
</cascade>
|
||||
|
@ -26,6 +26,7 @@ Doctrine\Tests\ORM\Tools\Export\User:
|
||||
cascade: [ persist ]
|
||||
inversedBy: user
|
||||
orphanRemoval: true
|
||||
fetch: EAGER
|
||||
manyToOne:
|
||||
mainGroup:
|
||||
targetEntity: Doctrine\Tests\ORM\Tools\Export\Group
|
||||
@ -37,6 +38,7 @@ Doctrine\Tests\ORM\Tools\Export\User:
|
||||
number: ASC
|
||||
cascade: [ persist, merge ]
|
||||
orphanRemoval: true
|
||||
fetch: LAZY
|
||||
interests:
|
||||
targetEntity: Doctrine\Tests\ORM\Tools\Export\Interests
|
||||
mappedBy: user
|
||||
@ -45,6 +47,7 @@ Doctrine\Tests\ORM\Tools\Export\User:
|
||||
manyToMany:
|
||||
groups:
|
||||
targetEntity: Doctrine\Tests\ORM\Tools\Export\Group
|
||||
fetch: EXTRA_LAZY
|
||||
joinTable:
|
||||
name: cms_users_groups
|
||||
joinColumns:
|
||||
|
Loading…
Reference in New Issue
Block a user