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
Relationships not respecting jsonapi standard outside controller. ( It's actually a serializer lookup problem ) #2095
Comments
I did some debugging. And this is as far as got til now.
From controller using hash[assotiation.key] has
and assotiation variable has
From rspec using hash[assotiation.key] has
and assotiation variable has
someone has any clue why the difference? |
Ok the serializer lookup is causing the problem due to namespacing.
I think it would be better to look first in the serializer to see if the serializer was defined (I did define it), then look in the same namespace and finally look in the root namespace. |
@fazelmk Thanks so much for this! I'm sorry you had to read through that json api relationships code. It's a beast! What do you think we should do to help future us? |
@bf4 this is what I would do. If the serializer for the relationship was defined (as the code bellow shows) it should use it.
Basic lookup (leave some common use cases not treated) Accurate lookup As the example I got namespace V1::Admin, if I didn't declare the serializer it could be V1::Admin or just V1 if it's a serializer outside the admin namespace. This would cover almost all the use cases. Leaving cross-version (which I think shouldn't be treated) and models in sub-domains of the serilizer domain (which we wouldn't have at hand to do lookup). This exceptions can be treated by declare the serializer for the relationship in the current serializer, so it won't be a problem for the user. I didn't dig up enough to find the lookup code. If you point me in the right direction I can make a PR for this. |
@fazelmk I just want to acknowledge I've read this. I'm spread pretty thinly and haven't yet read it carefully enough to make a suggestion. |
Jesus, this saved me a day lol. Thanks @fazelmk |
Tried debugging but didn't get anywhere. Maybe a problem caused by namespace.
Using
Serializers
Expected behavior vs actual behavior
Behavior outside controller
Behavior inside controller
The text was updated successfully, but these errors were encountered: