Skip to content

Commit

Permalink
Handle ManyToMany relations in embedded lists
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Aug 25, 2018
1 parent dece12c commit 301bdf5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Helper/EmbeddedListHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace AlterPHP\EasyAdminExtensionBundle\Helper;

use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Symfony\Component\PropertyAccess\PropertyAccess;
Expand Down Expand Up @@ -118,6 +119,7 @@ public function guessDefaultFilter(string $entityFqcn, string $parentEntityPrope
if (
$parentEntityFqcn === $assoc['targetEntity']
&& $parentEntityProperty === $assoc['inversedBy']
&& isset($assoc['joinColumns'])
&& 1 === count($assoc['joinColumns'])
) {
$assocFieldPart = 'entity.'.$assoc['fieldName'];
Expand All @@ -126,6 +128,19 @@ public function guessDefaultFilter(string $entityFqcn, string $parentEntityPrope
);

return [$assocFieldPart => $assocIdentifierValue];
} elseif (
$parentEntityFqcn === $assoc['targetEntity']
&& $parentEntityProperty === $assoc['inversedBy']
&& isset($assoc['joinTable'])
) {
$relatedItems = PropertyAccess::createPropertyAccessor()->getValue(
$parentEntity, $parentEntityProperty
);
$itemIds = $relatedItems->map(function ($entity) {
return $entity->getId();
});

return ['entity.id' => $itemIds->toArray()];
}
}

Expand Down

0 comments on commit 301bdf5

Please sign in to comment.