jeudi 10 décembre 2015

How to include nested relationships?

At http://ift.tt/1jQFCiC

Articles belongs to an author. Articles have many comments. Comments belongs to a user.

Trying to understand how to include nested relationships. Take for example: http://ift.tt/1NXNzAt

You would expect:

{
  data: [
    {
      id: 1,
      type: "articles",
      attributes: { ... },
      relationships: {
        author: { ... },
        comments: [{ ... }, { ... }],
      },
      ...
    },
    { ... }
  ]
  included: [
    {
      author: { ... },
      comment: { ... },
      comment: { ... }
    {
  ]
}

Now lets say, you wanted to include the users who wrote those comments. http://ift.tt/1jQFAHj

Should the response look like:

{
  data: [
    {
      id: 1,
      type: "articles",
      attributes: { ... },
      relationships: {
        author: { ... },
        comments: [{ ... }, { ... }]
      },
      ...
    },
    { ... }
  ]
  included: [
    {
      author: { ... },
      comment: { ... },
      comment: { ... },
      user: { ... },
      user: { ... }
    {
  ]
}

Should users (users who wrote the comments) also be in the relationship node, or just in the included node?

If in the relationship node. Should user be nested inside data.relationships.comments? How would that look?




Aucun commentaire:

Enregistrer un commentaire