Skip to content

Commit

Permalink
Fix problems with relations
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Feb 17, 2022
1 parent 8700fb6 commit 65222a8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/ObjectInfo/DoctrineORMInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace A2lix\AutoFormBundle\ObjectInfo;

use A2lix\AutoFormBundle\Form\Type\AutoFormType;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
Expand Down Expand Up @@ -62,19 +61,19 @@ private function getAssocsConfig(ClassMetadata $metadata, array $assocNames): ar
$assocsConfigs = [];

foreach ($assocNames as $assocName) {
if (!$metadata->isAssociationInverseSide($assocName)) {
$associationMapping = $metadata->getAssociationMapping($assocName);

if (isset($associationMapping['inversedBy'])) {
continue;
}

$class = $metadata->getAssociationTargetClass($assocName);

if ($metadata->isSingleValuedAssociation($assocName)) {
$nullable = ($metadata instanceof ClassMetadataInfo) && isset($metadata->discriminatorColumn['nullable']) && $metadata->discriminatorColumn['nullable'];

$assocsConfigs[$assocName] = [
'field_type' => AutoFormType::class,
'data_class' => $class,
'required' => !$nullable,
'required' => false,
];

continue;
Expand Down

0 comments on commit 65222a8

Please sign in to comment.