What is the correct way (if there is one) to @Exclude the "discriminator" column existent in entities that uses doctrine inheritance mapping?
I was able to exclude it by using groups but this is just a workaround and I believe won't work for long, see https://github.com/schmittjoh/JMSSerializerBundle/issues/506.
You can prevent the Doctrine DiscriminatorColumn from being added to the serialized output by using the _disabled_ property of the @Discriminator annotation like this:
/**
* @Discriminator(disabled=true)
*/
abstract class Vehicle { }
class Car extends Vehicle { }
This works for me. I am not using deserialization on this hierarchy of entities though. For more information, have a look at the usages of the Discriminator Annotation in the serializer repo
Thank you very much @mostertb.
For YAML reference:
Namespace\Entity:
discriminator:
disabled: true
It's funny, this question is asking how to exclude it but I'd like to know how to include it! I want to use Doctrine's discriminator column instead of having a separate one for the serializer but I just can't seem to include it whatever I do.
@andyexeter If you are in an exclude_all policy, this is what I do to have it, with this config example on BaseEntity:
discriminator:
field_name: type
disabled: false
map:
car: App\EntityBundle\Entity\AppUser\VehiculeCar
bike: App\EntityBundle\Entity\AppUser\VehiculeBike
Add the "Default" group to your serialized context when serializing the entity (this damn discriminator field seems to obey only that), and you should have it in serialized as a "type" field in your serialization result.
@bcastagna A belated thank you! I shelved this project a year ago and have just started to look at it again, your solution works :)
Most helpful comment
You can prevent the Doctrine DiscriminatorColumn from being added to the serialized output by using the _disabled_ property of the
@Discriminatorannotation like this:This works for me. I am not using deserialization on this hierarchy of entities though. For more information, have a look at the usages of the Discriminator Annotation in the serializer repo