# Ember data and relationships. Performance

**URL:** https://discuss.emberjs.com/t/ember-data-and-relationships-performance/3733
**Category:** Performance
**Created:** [January 1, 2014, 9:49pm UTC](https://discuss.emberjs.com/t/ember-data-and-relationships-performance/3733 "2014-01-01T21:49:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![bill](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/bill/32/5167_2.png) [@bill](https://discuss.emberjs.com/u/bill)
#### Post date: [January 1, 2014, 9:49pm UTC](https://discuss.emberjs.com/t/ember-data-and-relationships-performance/3733/1 "2014-01-01T21:49:56Z")

</div>

Hi all:

This is my second Ember Application, and the following problem has been a reoccurring theme.

I am using the Canary build of both Ember js and Ember data with query params enabled.

Say we have the following relationships:

- A has many B
- A has many C
- A has many D
- A has many E

Model B, C, D, E are huge models and resource heavy for rendering. So loading them ALL the time is not optimal.

Say if my application has a dashboard that allows for a quick glance of the state of the application, and it focuses on model A. I don’t need to display anything from B, C, D, E. So the JSON will not return the relationship ID array from the `example.com/api/a` endpoint.

And if the user clicks to the `show` route of model A then **How should I load models B, C, D, E?**

Thanks All

---

<div class="post-metadata">

### Author: ![gordon\_kristan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/gordon_kristan/32/14862_2.png) [@gordon\_kristan](https://discuss.emberjs.com/u/gordon_kristan)
#### Post date: [January 1, 2014, 11:13pm UTC](https://discuss.emberjs.com/t/ember-data-and-relationships-performance/3733/2 "2014-01-01T23:13:27Z")

</div>

I’ve been using a very old version of Ember Data for a long time, and I _just_ updated to the latest version a few days ago. Because of this, take what I say with a grain of salt. 😄 But I believe that Ember Data only loads records/relationships lazily. So you should return the IDs for B, C, D, E along with the JSON for A, and then Ember Data should load the records for them automatically as soon as you reference them.

EDIT: Almost forgot. You must include the `async: true` option for this to work.

```auto
App.A = DS.Model.extend({
    b: DS.hasMany('b', { async: true });
});

```

---

<div class="post-metadata">

### Author: ![bill](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/bill/32/5167_2.png) [@bill](https://discuss.emberjs.com/u/bill)
#### Post date: [January 3, 2014, 3:47pm UTC](https://discuss.emberjs.com/t/ember-data-and-relationships-performance/3733/3 "2014-01-03T15:47:46Z")

</div>

This was the solution. Thanks @gordon_kristan!

It never occurred to me that Ember will only lazy load _iff_ the relationship is being accessed.
