Commit 4918d3e1 authored by romanb's avatar romanb

[2.0] Simplification and fix to cascades.

parent 08694d18
......@@ -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);
}
/**
......@@ -361,6 +359,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.
* The data comes from the association navigated from $sourceEntity
......
......@@ -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');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment