Ver código fonte

fixes a bug when property contains an association using inheritance

Johannes M. Schmitt 12 anos atrás
pai
commit
b734652780

+ 13 - 0
src/JMS/Serializer/Metadata/Driver/DoctrineTypeDriver.php

@@ -20,6 +20,7 @@ namespace JMS\Serializer\Metadata\Driver;
 
 use Doctrine\Common\Persistence\ManagerRegistry;
 use Metadata\Driver\DriverInterface;
+use Doctrine\ORM\Mapping\ClassMetadataInfo;
 
 /**
  * This class decorates any other driver. If the inner driver does not provide a
@@ -92,6 +93,18 @@ class DoctrineTypeDriver implements DriverInterface
                 $propertyMetadata->setType($fieldType);
             } elseif ($doctrineMetadata->hasAssociation($propertyName)) {
                 $targetEntity = $doctrineMetadata->getAssociationTargetClass($propertyName);
+
+                if (null === $targetMetadata = $this->tryLoadingDoctrineMetadata($targetEntity)) {
+                    continue;
+                }
+
+                // For inheritance schemes, we cannot add any type as we would only add the super-type of the hierarchy.
+                // On serialization, this would lead to only the supertype being serialized, and properties of subtypes
+                // being ignored.
+                if ($targetMetadata instanceof ClassMetadataInfo && ! $targetMetadata->isInheritanceTypeNone()) {
+                    continue;
+                }
+
                 if ($doctrineMetadata->isSingleValuedAssociation($propertyName)) {
                     $propertyMetadata->setType($targetEntity);
                 } else {