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

Relationship type match JsonApiResource type #18

Open
malmberC opened this issue Dec 10, 2018 · 1 comment
Open

Relationship type match JsonApiResource type #18

malmberC opened this issue Dec 10, 2018 · 1 comment

Comments

@malmberC
Copy link

Hi.
We have found a minor bug with crnk relationship. In a relationship the type specifies which repository to fetch the data from. But in our case the model of repository is a subclass of the object used in the model of the request.

Example:
{ "data": { "type": "human", "attributes": { "name": "Jon Smith" }, "relationships": { "pet": { "data": { "type": "dog", "id": "123" } },"pet": { "data": { "type": "cat", "id": "123" } } } } }

here both "cat" and "dog" are subclasses of "animal". The ID is for dog. Human have
@JsonApiRelation(lookUp = LookupIncludeBehavior.AUTOMATICALLY_ALWAYS) private Animal animal;
it will fail for "cat" as the repository of "dog" will throw "ResourceNotFound". The bug is that if the ID of said object from repository doesn't match the type specified on the relationship but both of them are subclasses in what they are trying to populate.

Shouldn't the relationship type match the object jsonapiresource type?
{ "data": { "type": "human", "attributes": { "name": "Jon Smith" }, "relationships": { "pet": { "data": { "type": "animal", "id": "123" } },"pet": { "data": { "type": "animal", "id": "123" } } } } }
As this is what is specify in Human class?

Thanks,
Chris

@remmeier
Copy link
Contributor

hi, do you have an exception? not yet sure at what point it fails, but inheritance is in general sipported. the example abobe repeats the pet relationship, i guess that is an error in that snippet? it is good that the relationship data section lists the subtypes rather than animal as type. that allows to quickly determine its actual type.

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

2 participants