Multiple hasMany relationships not loading when doing a find


#1

I have an “organization” model with multiple hasMany relationships:

  users: DS.hasMany('user',{async:true}),
  templates: DS.hasMany('template',{async:true}),

When I use this model in a handlebars template to display the model, it pulls in both the relationships. But when I try to create a new user and load in the organization via:

this.store.find('organization');

it is not pulling in the relationships for templates, and vice-versa, when I create a new template and load in the organization, it doesn’t load in the users relationship. What could I be missing, or what do I need to do differently?


#2

If the relationships are async, they aren’t going to be loaded unless they’re called. So if you create a new user currentUser and set its organization like this:

currentUser.set("organization", this.store.find('organization', 1))

you’ll make a request to your API for that organization instance, but you won’t get its templates unless you also do something like this:

currentUser.get("organization.templates")

(I’m leaving out the promise-resolving part here, for simplicity’s sake.)


#3

Thank you so much, that solved it.