-
-
Notifications
You must be signed in to change notification settings - Fork 889
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
Wrong attributes serialized when embedding multiple different inherited entities #1025
Comments
After Debugging a little I see that the method The Changing line 130 of AbstractItemNormalizer so that it uses |
@soyuka do you have any idea how to fix this? It's a major bug. |
I have found a few more places in the code which might have to be changed.
In my current project it works fine now, but I found another bug. I will
post more information tomorrow.
|
Thanks! Don't hesitate to post a WIP Pull Request, it will allow us to review early. |
@dunglas never noticed this when I'm using parent classes I don't usually need a Resource on the parent class... Indeed this is a major bug and I have no clue why it does this, it has to do with how caching works (keep properties of first class, because |
Yes, I usually avoid to use inheritance for entities too. Maybe should be just remove the ability to use inheritance with API Platform, IMO it's a bad practice, it makes the code complexer and leads to bugs... |
Sometimes it's inevitable. Though, having a Anyway, we can maybe find an easy fix for this and still keep this "feature". |
While building my data model I didn't feel very good about it either. Or in my project I have an entity that consists of many different components in one Collection. These componentes can be of different type and thus have different properties. It wouldn't make much sense to only serialize the shared properties and the parent properties are serialized, like @soyuka suggests. But I am open for suggestions how I can solve this problem without inheritance. Perhaps I started wrong from the beginning on. The work in progress PR is coming tomorrow morning CET. |
I am currently busy with a project which has the deadline tomorrow. I decided to remove the inheritance in this case just to get it over with. After that I will create a PR. I noticed strange behaviour with deserializing properties dependent on whether Doctrines eager loading is enabled or not. |
Here is what I mean with the last sentence: |
It seems like this is not only occuring with inheritance. |
I'm running in to this issue as well, and would like to see it fixed instead of the feature being removed. Especially since Doctrine is basically a first class citizen for this project. There are good reasons to have mixed types in a single collection. For example, I have a Document entity that has bunch of ChangeEvents attached to it. These events are all similar, but contain slightly different data depending on whether they are SubjectChangeEvent or AuthorChangeEvent, etc. It really doesn't make sense for these child entities to be completely separate. |
@bwegrzyn there are better solutions now to handle mixed types, namely JSON columns (with https://github.com/dunglas/doctrine-json-odm). If someone want to work on a fix, I'll be glad to merge it. But I was against supporting |
@dunglas Thanks for the link. I will take a look at it. I'm already using something similar in my project, but the downfall of this approach is that you cannot have relations. In my case, the status of a Document might change, so the StatusChangeEvent entity has a relation to the Status entity. I'm definitely open to refactoring my implementation of the ChangeEvent entity I have. I'm just not sure how to do it effectively without using inheritance and having them be properly searchable. |
When serializing an related entity which hast some kind of entity with inheritance embedded (doesn't actually matter if it's single table or joined).
The properties of the parent class are serialized, and ONLY the properties of one of the child classes. But for all entites, regardless of their type.
This is a sample setup:
When retrieving a RelatedEntity which has a relation to one FooChild and one BarChild the result looks like this:
But the FooChild Entity should not have the property
bar
, butfoo
instead. And in my testing date the value ofbar
on the BarChild entity is actually not an empty string...The text was updated successfully, but these errors were encountered: