Ember data and relationships. Performance


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


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. :smile: 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.

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


This was the solution. Thanks @gordon_kristan!

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