I have an entity which defines inheritance like this:
* @DiscriminatorColumn(name=\"type\", type=\"string\")
* @DiscriminatorMap({\"text\" = \"TextAttribute\
Another slicker and faster way than to overload the method in every child or define a constant in every child is to use reflection class to retrieve the name of the class without the namespace :
public function getType() {
return (new \ReflectionClass($this))->getShortName();
}
It also works in any php version since php 5
It might not return exactly the discriminator name depending on your discriminator map declaration but it will return the child entity name (the class name) which is a great way to name and distinguish the different subentities
Without a need to define anything in the subclasses.
It's possible either with the EntityManager or using the DocumentManager.
$documentManager->getClassMetadata(get_class($entity))->discriminatorValue;