From ee1aee2fa8a841008ce90b438eeab72065a41520 Mon Sep 17 00:00:00 2001 From: David Maicher Date: Sat, 24 Feb 2024 18:18:55 +0100 Subject: [PATCH] fix mapping objects vs arrays --- src/FieldDescription/FieldDescriptionFactory.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/FieldDescription/FieldDescriptionFactory.php b/src/FieldDescription/FieldDescriptionFactory.php index bc1c1736a..747a2ec9b 100644 --- a/src/FieldDescription/FieldDescriptionFactory.php +++ b/src/FieldDescription/FieldDescriptionFactory.php @@ -14,6 +14,7 @@ namespace Sonata\DoctrineORMAdminBundle\FieldDescription; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\ORM\Mapping\ClassMetadata; use Sonata\AdminBundle\FieldDescription\FieldDescriptionFactoryInterface; use Sonata\AdminBundle\FieldDescription\FieldDescriptionInterface; @@ -29,11 +30,19 @@ public function create(string $class, string $name, array $options = []): FieldD { [$metadata, $propertyName, $parentAssociationMappings] = $this->getParentMetadataForProperty($class, $name); + $associationMapping = $metadata->associationMappings[$propertyName] ?? []; + + if ($associationMapping instanceof AssociationMapping) { + $associationMappingType = $associationMapping->type(); + $associationMapping = (array) $associationMapping; + $associationMapping['type'] = $associationMappingType; + } + return new FieldDescription( $name, $options, - $metadata->fieldMappings[$propertyName] ?? [], - $metadata->associationMappings[$propertyName] ?? [], + (array) ($metadata->fieldMappings[$propertyName] ?? []), + $associationMapping, $parentAssociationMappings, $propertyName );