Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude the "discriminator" column for serialized entities #515

Closed
renan-taranto opened this issue Apr 15, 2016 · 5 comments
Closed

Exclude the "discriminator" column for serialized entities #515

renan-taranto opened this issue Apr 15, 2016 · 5 comments

Comments

@renan-taranto
Copy link

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 #506.

@mostertb
Copy link

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

@renan-taranto
Copy link
Author

Thank you very much @mostertb.
For YAML reference:

Namespace\Entity:
    discriminator:
        disabled: true

@andyexeter
Copy link

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.

@bcastagna
Copy link

bcastagna commented Oct 26, 2017

@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.

@andyexeter
Copy link

@bcastagna A belated thank you! I shelved this project a year ago and have just started to look at it again, your solution works :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants