1
0
mirror of synced 2025-02-12 10:19:24 +03:00

[2.0] Simplification and fix to cascades.

This commit is contained in:
romanb 2009-10-25 22:04:13 +00:00
parent 08694d1826
commit 4918d3e174
2 changed files with 23 additions and 10 deletions

View File

@ -51,7 +51,6 @@ abstract class AssociationMapping
*/ */
const FETCH_EAGER = 3; const FETCH_EAGER = 3;
public $cascades = array();
public $isCascadeRemove; public $isCascadeRemove;
public $isCascadePersist; public $isCascadePersist;
public $isCascadeRefresh; public $isCascadeRefresh;
@ -165,13 +164,12 @@ abstract class AssociationMapping
// Optional attributes for both sides // Optional attributes for both sides
$this->fetchMode = isset($mapping['fetch']) ? $this->fetchMode = isset($mapping['fetch']) ?
$mapping['fetch'] : self::FETCH_LAZY; $mapping['fetch'] : self::FETCH_LAZY;
$this->cascades = isset($mapping['cascade']) ? $cascades = isset($mapping['cascade']) ? $mapping['cascade'] : array();
(array)$mapping['cascade'] : array(); $this->isCascadeRemove = in_array('remove', $cascades);
$this->isCascadeRemove = in_array('remove', $this->cascades); $this->isCascadePersist = in_array('persist', $cascades);
$this->isCascadePersist = in_array('persist', $this->cascades); $this->isCascadeRefresh = in_array('refresh', $cascades);
$this->isCascadeRefresh = in_array('refresh', $this->cascades); $this->isCascadeMerge = in_array('merge', $cascades);
$this->isCascadeMerge = in_array('merge', $this->cascades); $this->isCascadeDetach = in_array('detach', $cascades);
$this->isCascadeDetach = in_array('detach', $this->cascades);
} }
/** /**
@ -361,6 +359,15 @@ abstract class AssociationMapping
return (bool) $this->joinTable; 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. * Loads data in $target domain object using this association.
* The data comes from the association navigated from $sourceEntity * The data comes from the association navigated from $sourceEntity

View File

@ -331,8 +331,14 @@ class AnnotationExporter extends AbstractExporter
if (isset($associationMapping->mappedByFieldName)) { if (isset($associationMapping->mappedByFieldName)) {
$typeOptions[] = 'mappedBy="' . $associationMapping->mappedByFieldName . '"'; $typeOptions[] = 'mappedBy="' . $associationMapping->mappedByFieldName . '"';
} }
if (isset($associationMapping->cascades) && $associationMapping->cascades) { if ($associationMapping->hasCascades()) {
$typeOptions[] = 'cascade={"' . implode('"', $associationMapping->cascades) . '"}'; $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) { if (isset($associationMapping->orphanRemoval) && $associationMapping->orphanRemoval) {
$typeOptions[] = 'orphanRemoval=' . ($associationMapping->orphanRemoval ? 'true' : 'false'); $typeOptions[] = 'orphanRemoval=' . ($associationMapping->orphanRemoval ? 'true' : 'false');