Skip to content

Commit

Permalink
Merge pull request Sylius#1467 from umpirsky/fix/issue-1343
Browse files Browse the repository at this point in the history
Unset many to many association mapings in LoadMetadataSubscriber
  • Loading branch information
Paweł Jędrzejewski committed May 7, 2014
2 parents 71121bc + 4640491 commit 738d290
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions EventListener/LoadMetadataSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ private function setAssociationMappings(ClassMetadataInfo $metadata, $configurat
$configuration->getMetadataDriverImpl()->loadMetadataForClass($parent, $parentMetadata);
if ($parentMetadata->isMappedSuperclass) {
foreach ($parentMetadata->getAssociationMappings() as $key => $value) {
if (ClassMetadataInfo::ONE_TO_MANY === $value['type'] ||
ClassMetadataInfo::ONE_TO_ONE === $value['type']) {
if ($this->hasRelation($value['type'])) {
$metadata->associationMappings[$key] = $value;
}
}
Expand All @@ -101,10 +100,22 @@ private function setAssociationMappings(ClassMetadataInfo $metadata, $configurat
private function unsetAssociationMappings(ClassMetadataInfo $metadata)
{
foreach ($metadata->getAssociationMappings() as $key => $value) {
if ($value['type'] === ClassMetadataInfo::ONE_TO_MANY ||
$value['type'] === ClassMetadataInfo::ONE_TO_ONE) {
if ($this->hasRelation($value['type'])) {
unset($metadata->associationMappings[$key]);
}
}
}

private function hasRelation($type)
{
return in_array(
$type,
array(
ClassMetadataInfo::MANY_TO_MANY,
ClassMetadataInfo::ONE_TO_MANY,
ClassMetadataInfo::ONE_TO_ONE
),
true
);
}
}

0 comments on commit 738d290

Please sign in to comment.