# Side loading data with JsonAPI links

**URL:** <https://discuss.emberjs.com/t/side-loading-data-with-jsonapi-links/9992>\
**Category:** Ember Data\
**Created:** [March 1, 2016, 10:38pm UTC](https://discuss.emberjs.com/t/side-loading-data-with-jsonapi-links/9992 "2016-03-01T22:38:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![patryk](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@patryk](https://discuss.emberjs.com/u/patryk)\
**Post date:** [March 1, 2016, 10:38pm UTC](https://discuss.emberjs.com/t/side-loading-data-with-jsonapi-links/9992/1 "2016-03-01T22:38:03Z")

</div>

I’ve been having a difficult time with this over the last two days with side loading data via the links attribute in a JsonAPI payload. Essentially I have a hasMany relationship where I attempt to lazy load the data. I have a nested API structure and want the call to look like this `/posts/1/comments`. I have this working using the RESTAdapter but it doesn’t work with the JSONAPIAdapter.

Post Model

> ```
> export default DS.Model.extend({
> name: DS.attr('string'),
> comments: DS.hasMany('comment', {async:true})
> });
> 
> ```

Comment Model

> ```
> export default DS.Model.extend({
> name: DS.attr('string'),
> post: DS.belongsTo('post')
> });
> 
> ```

JSON payload

> ```
> "data": [{
> "type": "posts",
> "id": "1",
> "attributes": {
> "id": 1
> "name": "my title"
> },
> "links": {
> "comments": "comments"
> }
> }]
> 
> ```

Template

> ```
> <ul>
> {{#each model as |post|}}
> {{#each post.comments as |comment|}}
> <li>{{comment.name}}</li>
> {{/each}}
> {{/each}}
> </ul>
> 
> ```

I have read many different posts and blogs about how Ember’s REST adapter uses links to load related data, and I do have this working with a REST adapter, although with a different payload to match the REST adapter’s expectations. I have tried many different combinations of payloads but nothing so far has worked.

---

<div class="post-metadata">

**Author:** ![emberigniter](https://avatars.discourse-cdn.com/v4/letter/e/aca169/32.png) [@emberigniter](https://discuss.emberjs.com/u/emberigniter)\
**Post date:** [March 5, 2016, 12:37am UTC](https://discuss.emberjs.com/t/side-loading-data-with-jsonapi-links/9992/2 "2016-03-05T00:37:25Z")

</div>

Hi @patryk,

Your payload should look like:

```
"data": [{
  "type": "posts",
  "id": "1",
  "attributes": {
    "id": 1
    "name": "my title"
  },
  relationships: {
    comments: {
      links: {
        related: "/posts/1/comments"
      }
    }
  }
}]

```

If you need some more guidance on how to generate `links`, there is something similar with the Github API in this article: [Fit Any Backend Into Ember with Custom Adapters & Serializers - Ember Igniter](http://emberigniter.com/fit-any-backend-into-ember-custom-adapters-serializers/) (search for `payload.repos_url`)

---

<div class="post-metadata">

**Author:** ![patryk](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@patryk](https://discuss.emberjs.com/u/patryk)\
**Post date:** [March 7, 2016, 9:39pm UTC](https://discuss.emberjs.com/t/side-loading-data-with-jsonapi-links/9992/3 "2016-03-07T21:39:53Z")

</div>

Awesome, this worked for me. Thank you.
