Mixed async/sideloaded for the same relation


I’ve just started the upgrade to Ember Data 1.0.0 beta2 and I’m having some problems with sideloading. Before you could just do:

App.RESTAdapter.configure('App.Foo', {sideloadAs: 'foos'})

… and then that entity would be sideloaded whenever it’s returned in the JSON payload.

Now when you want to have relations loaded lazily (on demand) you need to set async: true in the relation definition. However this seems to break sideloading. Is there some way to achieve both sideloading and asynchronous loading on the same relation?


I just ran into the same problem when testing (separate fixtures vs. side loaded data). The tests require that my hasManys have {async: true} set.

The solution seems to be something like this:

model: function() {
  var promise = this.store.find('foo', 1).then(function(foo) {
     return Ember.RSVP.all([foo, foo.bar, foo.baz]).then(data) { return data[0] });
  return promise;

Note that the (resolved) foo is in the list of promises for RSVP.all().

I don’t know if it is a good idea to do that in the model hook, neither if it works reliably, but for me it seems to do the trick.


Anything happened here?

Ember showed some warnings, when I had some keys in the root-hash of a response that didn’t map to a model, so the adapter didn’t know how to deserialize them.

This seems like the adapter should be able to sideload every known model I include in my responses.

But somehow only the model the request was explicitly sent for gets loaded in the store. The other ones don’t, even if a model-mapping for them exists.

Funny thing is, when I create a new record with an async belongsTo and the server fills the ID of the related record, Ember creates a dummy record for the needed relationship with all values undefined AND loads the data with a GET from the server when the dummy record is accessed.