#1130 DDC-3300 - re-mapping discriminator column at runtime (based on modified class metadata)
This commit is contained in:
parent
5a1a32297b
commit
c589b5d013
@ -30,6 +30,7 @@ use Doctrine\ORM\Events;
|
||||
use Doctrine\ORM\Id\BigIntegerIdentityGenerator;
|
||||
use Doctrine\ORM\Id\IdentityGenerator;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Exception;
|
||||
use ReflectionException;
|
||||
|
||||
/**
|
||||
@ -70,6 +71,30 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
*/
|
||||
private $embeddablesActiveNesting = array();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function loadMetadata($name)
|
||||
{
|
||||
/* @var $loaded string[] */
|
||||
$loaded = parent::loadMetadata($name);
|
||||
|
||||
foreach ($loaded as $className) {
|
||||
/* @var $metadata ClassMetadata */
|
||||
$metadata = $this->getMetadataFor($className);
|
||||
|
||||
if (! $metadata->discriminatorValue) {
|
||||
foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) {
|
||||
if ($metadata->name === $this->getMetadataFor($discriminatorClass)->getName()) {
|
||||
$metadata->discriminatorValue = $discriminatorValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $loaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EntityManagerInterface $em
|
||||
*/
|
||||
@ -270,9 +295,9 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
if ( ! $class->discriminatorColumn) {
|
||||
throw MappingException::missingDiscriminatorColumn($class->name);
|
||||
}
|
||||
} else if ($parent && !$class->reflClass->isAbstract() && !in_array($class->name, array_values($class->discriminatorMap))) {
|
||||
} else if (! $class->reflClass->isAbstract() && !in_array($class->name, array_values($class->discriminatorMap))) {
|
||||
// enforce discriminator map for all entities of an inheritance hierarchy, otherwise problems will occur.
|
||||
throw MappingException::mappedClassNotPartOfDiscriminatorMap($class->name, $class->rootEntityName);
|
||||
//throw MappingException::mappedClassNotPartOfDiscriminatorMap($class->name, $class->rootEntityName);
|
||||
}
|
||||
} else if ($class->isMappedSuperclass && $class->name == $class->rootEntityName && (count($class->discriminatorMap) || $class->discriminatorColumn)) {
|
||||
// second condition is necessary for mapped superclasses in the middle of an inheritance hierarchy
|
||||
|
Loading…
x
Reference in New Issue
Block a user