Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Collapsed cascade elements, if cascade-all. #158

Merged
merged 5 commits into from

3 participants

@goetas

Collapsed cascade elements, if cascade-all.
(better readability for generated xml)

@goetas goetas Collapsed cascade elements, if cascade-all.
(better readability for generated xml)
97321a1
@jwage
Owner

If we were to include this change we should probably consider adding it across all the drivers, as well as adding unit tests.

lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php
@@ -276,6 +276,9 @@ class XmlExporter extends AbstractExporter
if ($associationMapping['isCascadeDetach']) {
$cascade[] = 'cascade-detach';
}
+ if(count($cascade)==5){
@jwage Owner
jwage added a note

Coding standards, this line should be:

if (count($cascade) === 5) {
@goetas
goetas added a note

Done

@goetas
goetas added a note

Do you use pear code sniffer detect coding standards errors? where i can find the xml config file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
goetas added some commits
@goetas

Added some tests.

@goetas

added right test.
cb76222 was an error

@beberlei
Owner

Can you add this for yml and annotations aswell?

@goetas

done

@beberlei beberlei merged commit 0d4e062 into doctrine:master
@elHornair elHornair referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@goetas goetas deleted the goetas:cascade-all branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 18, 2011
  1. @goetas

    Collapsed cascade elements, if cascade-all.

    goetas authored
    (better readability for generated xml)
Commits on Oct 24, 2011
  1. @goetas

    Coding standards

    goetas authored
  2. @goetas

    Collapse cascade persist, remove, refresh, detach, merge into

    goetas authored
    cascade-all (implemented currently only for XML annotation)
Commits on Oct 26, 2011
  1. @goetas

    Collapse cascade all test

    goetas authored
  2. @goetas
This page is out of date. Refresh to see the latest.
View
3  lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php
@@ -276,6 +276,9 @@ public function exportClassMetadata(ClassMetadataInfo $metadata)
if ($associationMapping['isCascadeDetach']) {
$cascade[] = 'cascade-detach';
}
+ if (count($cascade) === 5) {
+ $cascade = array('cascade-all');
+ }
if ($cascade) {
$cascadeXml = $associationMappingXml->addChild('cascade');
foreach ($cascade as $type) {
View
3  lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php
@@ -147,6 +147,9 @@ public function exportClassMetadata(ClassMetadataInfo $metadata)
if ($associationMapping['isCascadeDetach']) {
$cascade[] = 'detach';
}
+ if (count($cascade) === 5) {
+ $cascade = array('all');
+ }
$associationMappingArray = array(
'targetEntity' => $associationMapping['targetEntity'],
'cascade' => $cascade,
View
28 tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php
@@ -324,7 +324,33 @@ public function testInversedByIsExported($class)
{
$this->assertEquals('user', $class->associationMappings['address']['inversedBy']);
}
-
+ /**
+ * @depends testExportDirectoryAndFilesAreCreated
+ */
+ public function testCascadeAllCollapsed()
+ {
+ $type = $this->_getType();
+ if ($type == 'xml') {
+ $xml = simplexml_load_file(__DIR__ . '/export/'.$type.'/Doctrine.Tests.ORM.Tools.Export.ExportedUser.dcm.xml');
+
+ $xml->registerXPathNamespace("d", "http://doctrine-project.org/schemas/orm/doctrine-mapping");
+ $nodes = $xml->xpath("/d:doctrine-mapping/d:entity/d:one-to-many[@field='interests']/d:cascade/d:*");
+ $this->assertEquals(1, count($nodes));
+
+ $this->assertEquals('cascade-all', $nodes[0]->getName());
+ } elseif ($type == 'yaml') {
+
+ $yaml = new \Symfony\Component\Yaml\Parser();
+ $value = $yaml->parse(file_get_contents(__DIR__ . '/export/'.$type.'/Doctrine.Tests.ORM.Tools.Export.ExportedUser.dcm.yml'));
+
+ $this->assertTrue(isset($value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade']));
+ $this->assertEquals(1, count($value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade']));
+ $this->assertEquals('all', $value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'][0]);
+
+ } else {
+ $this->markTestSkipped('Test aviable only for '.$type.' dirver');
+ }
+ }
public function __destruct()
{
# $this->_deleteDirectory(__DIR__ . '/export/'.$this->_getType());
View
10 tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml
@@ -35,6 +35,16 @@
</order-by>
</one-to-many>
+ <one-to-many field="interests" target-entity="Doctrine\Tests\ORM\Tools\Export\Interests" mapped-by="user" orphan-removal="true">
+ <cascade>
+ <cascade-refresh/>
+ <cascade-persist/>
+ <cascade-merge/>
+ <cascade-detach/>
+ <cascade-remove/>
+ </cascade>
+ </one-to-many>
+
<many-to-many field="groups" target-entity="Doctrine\Tests\ORM\Tools\Export\Group">
<cascade>
<cascade-all/>
View
5 tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml
@@ -34,6 +34,11 @@ Doctrine\Tests\ORM\Tools\Export\User:
number: ASC
cascade: [ persist, merge ]
orphanRemoval: true
+ interests:
+ targetEntity: Doctrine\Tests\ORM\Tools\Export\Interests
+ mappedBy: user
+ cascade: [ persist, merge, remove, refresh, detach ]
+ orphanRemoval: true
manyToMany:
groups:
targetEntity: Doctrine\Tests\ORM\Tools\Export\Group
Something went wrong with that request. Please try again.