Skip to content

Include only a link in the relationships object #296

Closed
@arielpontes

Description

@arielpontes

According to the JSONAPI specification, if I have an Article model with a to-many relationship to a Comment model and I want to express this when I retrieve an Article resource, there are multiple valid ways I can do this:

  1. Include the comments by default in the response, having a list of resource identifier objects in the relationships object and a list with the actual resource objects in the included object.
  2. Return a list of resource identifier objects in the relationships object only, without including the actual attributes of the comments.
  3. Include only a link (e.g. /articles/1/comments) in the relationships object.

I have a model that links to a lot of related objects so the 3rd option would be the best for me, but I can't configure the ResourceRelatedField to act like that. It always returns a data object with the full list of related resource identifiers. Is there a way I can avoid this? Or do I have to extend the class myself? Doesn't seem very trivial to do that in a clean way.

Ideally, since the JSONAPI specs accept these 3 options, I think this library should allow these 3 configurations out of the box.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions