Skip to content

Commit

Permalink
Resolving relationships with interface (doctrine#7670)
Browse files Browse the repository at this point in the history
  • Loading branch information
Th-julien committed Aug 27, 2020
1 parent 1e2ed07 commit 1242c0d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/Doctrine/ORM/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\DBAL\Types\Type;
use function class_exists;
use function interface_exists;

/**
* Performs strict validation of the mapping schema
Expand Down Expand Up @@ -97,7 +99,12 @@ public function validateClass(ClassMetadataInfo $class)
}

foreach ($class->associationMappings as $fieldName => $assoc) {
if (!class_exists($assoc['targetEntity']) || $cmf->isTransient($assoc['targetEntity'])) {
/**
* Resolving target entities from Interface or Abstract ex. resolve_target_entities
*/
$targetEntity = isset($cmf->getLoadedMetadata()[$assoc['targetEntity']])
? $cmf->getLoadedMetadata()[$assoc['targetEntity']]->name : $assoc['targetEntity'];
if ((! class_exists($assoc['targetEntity']) && ! interface_exists($assoc['targetEntity'])) || $cmf->isTransient($targetEntity)) {
$ce[] = "The target entity '" . $assoc['targetEntity'] . "' specified on " . $class->name . '#' . $fieldName . ' is unknown or not an entity.';

return $ce;
Expand Down

0 comments on commit 1242c0d

Please sign in to comment.