Ember-data route's model hook only fetches model properly with forced reload


#1

I have an application that requires two models in one of the routes. This is a repost of my stackoverflow post: http://stackoverflow.com/q/30016031/4859481

Here I use RSVP.hash to bundle the two promises into one and return them for the setupController. Somehow one of the records is not retrieved properly and does not contain any data (the server is not requested either). So the state of the record after the promise hash was resolved is still root.empty.

I currently use a workaround that calls a record.reload() from the server, which triggers a refetch, like so:

model: function(param){
  return Ember.RSVP.hash({
        activities: this.store.find('activity', {'component_id': param.component_id}),
        component: this.store.find('component', param.component_id)
    }).then(function(models){
        //move component manually from DS.RootState.empty to loaded.saved
        models.component.transitionTo('loaded.saved');

        //force reload returns a promise.
        return models.component.reload().then(function(component){
            return {component: component, activities: models.activities};
        });
    });
}

The Stack:

DEBUG: -------------------------------
DEBUG: Ember             : 1.11.1
DEBUG: Ember Data        : 1.0.0-beta.15
DEBUG: jQuery            : 1.11.2
DEBUG: Ember Simple Auth : 0.7.1
DEBUG: -------------------------------

I have started debugging the issue and realized that the record’s isEmpty property is set to false and thus the find does not hit the server. I

Since this workaround in my opinion does not look good to me, i feel I must have forgotten something, so my questions are:

  • Is there a better solution?
  • What is the root cause of this?
  • is the isEmpty property computed or set manually and if yes where?

If you require more information, I’m more than happy to provide it.