I was wondering why you use AnnotationReader in your DoctrineEventListener. Moreover this solution works only when using annotation.
The ClassMetadataInfo has a public discriminatorMap attribute. You can get all loaded map at runtime and you can call addDiscriminatorMapClass to add each mapping from the config.yml.
So the code would like this :
class DoctrineEventListener
{
...
public function loadClassMetadata(LoadClassMetadataEventArgs $event)
{
$metadata = $event->getClassMetadata();
$class = $metadata->getReflectionClass();
foreach ($this->mapping as $entityName => $map) {
if ($class->getName() == $map['entity']) {
// First solution
$discriminatorMap = array_merge($metadata->discriminatorMap, $map['map']);
$discriminatorMap = array_merge($discriminatorMap, array($entityName => $map['entity']));
$metadata->setDiscriminatorMap($discriminatorMap);
// Second solution
foreach ($map['map'] as $name => $entityClass) {
$metadata->addDiscriminatorMapClass($name, $entityClass);
}
}
}
}
}
I don't think you should automaticaly add the mapping with the entity name :
Hi @jbouzekri,
I think you have a valid point of view and I’m ok with this change. Please send me a pull-request so I can try out the changes and tag a new version.
Hi,
I was wondering why you use AnnotationReader in your DoctrineEventListener. Moreover this solution works only when using annotation.
The ClassMetadataInfo has a public discriminatorMap attribute. You can get all loaded map at runtime and you can call addDiscriminatorMapClass to add each mapping from the config.yml.
So the code would like this :
I don't think you should automaticaly add the mapping with the entity name :
Best regards