From 4918d3e174ef2cbcf971adadda1fd659f8b901a4 Mon Sep 17 00:00:00 2001 From: romanb Date: Sun, 25 Oct 2009 22:04:13 +0000 Subject: [PATCH] [2.0] Simplification and fix to cascades. --- .../ORM/Mapping/AssociationMapping.php | 23 ++++++++++++------- .../Export/Driver/AnnotationExporter.php | 10 ++++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/AssociationMapping.php b/lib/Doctrine/ORM/Mapping/AssociationMapping.php index 74e52c5df..e2280bf80 100644 --- a/lib/Doctrine/ORM/Mapping/AssociationMapping.php +++ b/lib/Doctrine/ORM/Mapping/AssociationMapping.php @@ -51,7 +51,6 @@ abstract class AssociationMapping */ const FETCH_EAGER = 3; - public $cascades = array(); public $isCascadeRemove; public $isCascadePersist; public $isCascadeRefresh; @@ -165,13 +164,12 @@ abstract class AssociationMapping // Optional attributes for both sides $this->fetchMode = isset($mapping['fetch']) ? $mapping['fetch'] : self::FETCH_LAZY; - $this->cascades = isset($mapping['cascade']) ? - (array)$mapping['cascade'] : array(); - $this->isCascadeRemove = in_array('remove', $this->cascades); - $this->isCascadePersist = in_array('persist', $this->cascades); - $this->isCascadeRefresh = in_array('refresh', $this->cascades); - $this->isCascadeMerge = in_array('merge', $this->cascades); - $this->isCascadeDetach = in_array('detach', $this->cascades); + $cascades = isset($mapping['cascade']) ? $mapping['cascade'] : array(); + $this->isCascadeRemove = in_array('remove', $cascades); + $this->isCascadePersist = in_array('persist', $cascades); + $this->isCascadeRefresh = in_array('refresh', $cascades); + $this->isCascadeMerge = in_array('merge', $cascades); + $this->isCascadeDetach = in_array('detach', $cascades); } /** @@ -360,6 +358,15 @@ abstract class AssociationMapping { return (bool) $this->joinTable; } + + public function hasCascades() + { + return $this->isCascadePersist || + $this->isCascadeRemove || + $this->isCascadeRefresh || + $this->isCascadeMerge || + $this->isCascadeDetach; + } /** * Loads data in $target domain object using this association. diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php index f69080168..5297f03e9 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php @@ -331,8 +331,14 @@ class AnnotationExporter extends AbstractExporter if (isset($associationMapping->mappedByFieldName)) { $typeOptions[] = 'mappedBy="' . $associationMapping->mappedByFieldName . '"'; } - if (isset($associationMapping->cascades) && $associationMapping->cascades) { - $typeOptions[] = 'cascade={"' . implode('"', $associationMapping->cascades) . '"}'; + if ($associationMapping->hasCascades()) { + $cascades = array(); + if ($this->isCascadePersist) $cascades[] = '"persist"'; + if ($this->isCascadeRemove) $cascades[] = '"remove"'; + if ($this->isCascadeDetach) $cascades[] = '"detach"'; + if ($this->isCascadeMerge) $cascades[] = '"merge"'; + if ($this->isCascadeRefresh) $cascades[] = '"refresh"'; + $typeOptions[] = 'cascade={' . implode(',', $cascades) . '}'; } if (isset($associationMapping->orphanRemoval) && $associationMapping->orphanRemoval) { $typeOptions[] = 'orphanRemoval=' . ($associationMapping->orphanRemoval ? 'true' : 'false');