Skip to content

Commit

Permalink
Prevent overriding existing association mappings
Browse files Browse the repository at this point in the history
If the metadata already has existing association mappings for the given
field, we won't override anything and leave it as is.
  • Loading branch information
vntw committed Jan 30, 2017
1 parent f563c74 commit f1150d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private function setAssociationMappings(ClassMetadataInfo $metadata, $configurat

if ($parentMetadata->isMappedSuperclass) {
foreach ($parentMetadata->associationMappings as $key => $value) {
if ($this->hasRelation($value['association'])) {
if ($this->isRelation($value['association']) && !isset($metadata->associationMappings[$key])) {
$metadata->associationMappings[$key] = $value;
}
}
Expand All @@ -115,18 +115,18 @@ private function unsetAssociationMappings(ClassMetadataInfo $metadata)
}

foreach ($metadata->associationMappings as $key => $value) {
if ($this->hasRelation($value['association'])) {
if ($this->isRelation($value['association'])) {
unset($metadata->associationMappings[$key]);
}
}
}

/**
* @param $type
* @param string $type
*
* @return bool
*/
private function hasRelation($type)
private function isRelation($type)
{
return in_array(
$type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function setAssociationMappings(ClassMetadataInfo $metadata, $configurat

if ($parentMetadata->isMappedSuperclass) {
foreach ($parentMetadata->getAssociationMappings() as $key => $value) {
if ($this->hasRelation($value['type'])) {
if ($this->isRelation($value['type']) && !isset($metadata->associationMappings[$key])) {
$metadata->associationMappings[$key] = $value;
}
}
Expand All @@ -114,18 +114,18 @@ private function unsetAssociationMappings(ClassMetadataInfo $metadata)
}

foreach ($metadata->getAssociationMappings() as $key => $value) {
if ($this->hasRelation($value['type'])) {
if ($this->isRelation($value['type'])) {
unset($metadata->associationMappings[$key]);
}
}
}

/**
* @param $type
* @param string $type
*
* @return bool
*/
private function hasRelation($type)
private function isRelation($type)
{
return in_array(
$type,
Expand Down

0 comments on commit f1150d6

Please sign in to comment.