JSONAPI, 1.13.4, and linked relationships


#1

I have an API url structure that is nested, like /users/1/posts that renders responses in JSON API. The /users/1 response renders like so:

{
  "data": {
    "type": "users"
    "attributes": {},
    "id": "1",
    "links": {"self": "https://api.domain.dev/v1/users/1"},
    "relationships": {
      "posts": {
        "links": {
          "related": "https://api.domain.dev/v1/users/1/posts",
          "self": "https://api.domain.dev/v1/users/1/relationships/posts"
        }
      }
    },
  },
}

I have seen the topics in the past regarding nested URL structure and people wanting this for the RESTAdapter, but I’m wondering how this situation is different now that we’re moving towards JSON API as a default.

For example, I can get my user resource just fine with the JSONAPIAdapter but I’m having a hard time figuring out how to get my product resource via the linked relationships.

I am hoping to just do something like this.store.findRecord('user', 1).get('posts') but so far that has been unsuccessful.

I feel like this is going to be a common thing that the JSONAPIAdapter and JSONAPISerializer should handle, and I know the guides are still forthcoming. Does anyone have any insight into this yet? Looking at the source in 1.13.4 it seems like this should ‘just work’ somehow but I’m not getting it.

Thanks to anyone who has the time for feedback or insights!!

Andy


#2

Ummmmm. Disregard. This all works as expected when your model hook is implemented correctly. In the above example this.store.findRecord('user', 1).get('posts') is incorrect. The correct usage is:

 return this.store.findRecord('user', 1).then(function(user) {
   return user.get('posts');
 });