# Recursive Sideloading

**URL:** <https://discuss.emberjs.com/t/recursive-sideloading/7283>\
**Category:** Ember Data\
**Created:** [February 10, 2015, 2:55pm UTC](https://discuss.emberjs.com/t/recursive-sideloading/7283 "2015-02-10T14:55:43Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [February 10, 2015, 2:55pm UTC](https://discuss.emberjs.com/t/recursive-sideloading/7283/1 "2015-02-10T14:55:43Z")

</div>

I have a request that sideloads data two level deep IE the sideloaded data also has data that is sideloaded.

```
{
  "group_measures": [{
    "id": 565,
    "group_id": 572,
    "measure_id": 47
  }],
  "measures": [{
    "id": 47,
  }],
  "group": {
    "id": 572,
    "group_measure_ids": [565]
  }
}

```

I’m loading a group in this example and the group measure is properly filled but the group\_measures measure attribute is null.

I’m currently digging through the source to figure out how this is happening. Does anyone know if ember-data recursively resolves sideloading? Also if you know where in the source I can find this behavior. I’m still digging around for it at the moment and haven’t isolated where it happens.

UPDATE

Ember does recursively resolve sideloading, though recursive isn’t really the best way to describe it since it just loads everything into the store and the resolving seems to happen outside the payload processing.

My problem was I had my group\_measure defined as

```
var GroupMeasure = DS.Model.extend({
  measureId: attr(),
  group: DS.belongsTo('group'),
  measure: DS.belongsTo('measure')
});

```

After removing measureId: attr() it works just fine. The measureId attr was the only way I could think of to be able to save a model with just the ID as opposed to having the whole record but that causes the record to not load properly. In fact out of the box saving with just the measureId didn’t work and I monkey patched it to force it to work so obviously this is not the way to do this…

---

<div class="post-metadata">

**Author:** ![kylecoberly](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/kylecoberly/32/15828_2.png) [@kylecoberly](https://discuss.emberjs.com/u/kylecoberly)\
**Post date:** [February 10, 2015, 3:57pm UTC](https://discuss.emberjs.com/t/recursive-sideloading/7283/2 "2015-02-10T15:57:41Z")

</div>

I believe the recursive models still need to be “unpacked”, eg. be inside of root-level objects. I don’t think you can just nest them in place.

---

<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:** [February 10, 2015, 4:08pm UTC](https://discuss.emberjs.com/t/recursive-sideloading/7283/3 "2015-02-10T16:08:03Z")

</div>

@kylecoberly I updated the question with my payload I think I’m “unpacking” it but I maybe interpreting your meaning incorrectly.

Has it been your experience that ember will recursively resolve sideloading?

---

<div class="post-metadata">

**Author:** ![kylecoberly](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/kylecoberly/32/15828_2.png) [@kylecoberly](https://discuss.emberjs.com/u/kylecoberly)\
**Post date:** [February 10, 2015, 4:42pm UTC](https://discuss.emberjs.com/t/recursive-sideloading/7283/4 "2015-02-10T16:42:06Z")

</div>

Your response is structured correctly- I think the problem is that you’re calling things like “group\_measure\_ids” instead of “groupMeasures.” That’s adapter/serializer specific though. Mine looks more like the example from the docs:

```
{
  "post": {
    "id": 1,
    "title": "Node is not omakase",
    "comments": [1, 2, 3]
  },

  "comments": [{
    "id": 1,
    "body": "But is it _lightweight_ omakase?"
  },
  {
    "id": 2,
    "body": "I for one welcome our new omakase overlords"
  },
  {
    "id": 3,
    "body": "Put me on the fast track to a delicious dinner"
  }]
}

```

---

<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:** [February 10, 2015, 6:01pm UTC](https://discuss.emberjs.com/t/recursive-sideloading/7283/5 "2015-02-10T18:01:11Z")

</div>

@kylcoberly thanks for your response. I’m using ActiveModelSerializer which does seem to accept this formatting as other sideloaded models work fine. In this example the group\_measures get loaded but the measures on the group measures do not.

You’re comment has got me thinking to look deeper into ActiveModelSerializer.
