# Nested 'Linked-list' model in Ember-data

**URL:** https://discuss.emberjs.com/t/nested-linked-list-model-in-ember-data/7433
**Category:** Ember Data
**Created:** [March 2, 2015, 6:06pm UTC](https://discuss.emberjs.com/t/nested-linked-list-model-in-ember-data/7433 "2015-03-02T18:06:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![jorge\_lainfiesta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jorge_lainfiesta/32/11024_2.png) [@jorge\_lainfiesta](https://discuss.emberjs.com/u/jorge_lainfiesta)
#### Post date: [March 2, 2015, 6:06pm UTC](https://discuss.emberjs.com/t/nested-linked-list-model-in-ember-data/7433/1 "2015-03-02T18:06:14Z")

</div>

Hello,

I’ve been using Ember CLI to develop an API and it’s been interesting to get into the ‘ember way’ but I’ve found a quite tough situation I don’t know how I should proceed. I’ll present my models case:

1. Let `project` be a model with several info attributes such as _name_.

2. Let `structureRow` be another model with some info attributes, a _parent_`structureRow` and a _next_`structureRow`.

3. A `project` holds a `structurerow`.

Now I think of two possible directions to address this:

- I set up my backend API to give me the rendered structure of the project loaded, with all the relations resolved to certain depth instead of giving me references.

- I set up my backend API to give me references only and resolve them as needed in the frontend. However, I don’t know how I could make it using ember-data, given the strong convention with routes and templates.

What would you recommend to I set this up in an ember-way instead of writing some arbitrary AJAX handling in a controller?

Thanks!

---

<div class="post-metadata">

### Author: ![varblob](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/varblob/32/10304_2.png) [@varblob](https://discuss.emberjs.com/u/varblob)
#### Post date: [March 2, 2015, 10:16pm UTC](https://discuss.emberjs.com/t/nested-linked-list-model-in-ember-data/7433/2 "2015-03-02T22:16:02Z")

</div>

Either ways works. Personally I [sideload](http://emberjs.com/guides/models/the-rest-adapter/#toc_sideloaded-relationships) data that I know I will need wherever possible to cut down on total requests. Eventually I may have it so that the api supports an include query param that specifies which things to sideload and which not to.

If you don’t want to sideload data / want tho front end to resolve the relationships add the async attribute to your belongs to or has many.

```
DS.belongsTo('parent', { async: true })

```

---

<div class="post-metadata">

### Author: ![jorge\_lainfiesta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jorge_lainfiesta/32/11024_2.png) [@jorge\_lainfiesta](https://discuss.emberjs.com/u/jorge_lainfiesta)
#### Post date: [March 3, 2015, 3:14pm UTC](https://discuss.emberjs.com/t/nested-linked-list-model-in-ember-data/7433/3 "2015-03-03T15:14:19Z")

</div>

Thanks vablob, I’ll sideload relationships then. I was worried about having to many http requests by resolving every single relation on the frontend.

Just another question: if I sideload the data, will Ember notice it and populate de appropriate models or do I have to somehow tell Emeber I’m sideloading?

---

<div class="post-metadata">

### Author: ![varblob](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/varblob/32/10304_2.png) [@varblob](https://discuss.emberjs.com/u/varblob)
#### Post date: [March 3, 2015, 5:03pm UTC](https://discuss.emberjs.com/t/nested-linked-list-model-in-ember-data/7433/4 "2015-03-03T17:03:01Z")

</div>

Assuming your json payload matches the adapter you’re using it should just work.

---

<div class="post-metadata">

### Author: ![jorge\_lainfiesta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jorge_lainfiesta/32/11024_2.png) [@jorge\_lainfiesta](https://discuss.emberjs.com/u/jorge_lainfiesta)
#### Post date: [March 3, 2015, 5:34pm UTC](https://discuss.emberjs.com/t/nested-linked-list-model-in-ember-data/7433/5 "2015-03-03T17:34:07Z")

</div>

Nice, I just tried it and it simply works. Thanks!
