Skip to content

Relationship type match JsonApiResource type #18

@malmberC

Description

@malmberC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions