0

Good day,

Does removing of links.related on my JSON response will affect any Ember-Data relationship fetching?

relationships": {
  "comments": {
    "links": {
      "related": "http://localhost:3099/api/v1/articles/1/comments"
    },
    "data": [
      {
        "type": "comments",
        "id": 1
      },
      {
        "type": "comments",
        "id": 2
      },
      { ... More comments here ... }
    ]
  }
}

I've read this article : https://thejsguy.com/2016/02/21/handling-nested-resources-in-ember-data.html and this points me to Ember data uses those links internally to fetch the related data so I won't have to access those URLs and make requests to them. I need more concrete opinion before we make any changes to our API.

JAKITOVZ
  • 41
  • 2
  • Could you please give some more information about your motivation? Why do you want to do the `links.related` for relationships? – jelhan Jun 29 '18 at 07:28

1 Answers1

0

The related link is used when you don't specify data. Specifying both is redundant.

An example use-case:

You load a lit of blog posts, each has many comments. You don't want to load the comments yet tho. So you specify a relationship with a related link and no data. When the user clicks on the blog post you show the comments. Ember then will automatically load the comments from the specified link.

Lux
  • 17,835
  • 5
  • 43
  • 73
  • You are not taking pagination on relationship into account. As far as I understood the JSON API spec `data` must not include all relationships. If it does not include all (and meta indicates that it's paginated), `links.related` provides information which endpoint should be used to fetch the other ones. Also it might be useful for reloading related data. But I'm not quite sure how ember-data uses it in all edge cases by default. – jelhan Jun 30 '18 at 22:28