Use unloaded relationship for model


#1

I have a route, which sometimes is loaded immediately after signing in, that uses for its model a property of the current user, which might not be loaded yet.

model: function() {
  var session = this.controllerFor('session'),
      user = session.get('user'),
      company = user.get('isLoading') ?
        user._loadingPromise.then(function(u) { return u.get('company'); }) :
        new Ember.RSVP.Promise(function(resolve) { resolve(user.get('company')); });

  return company;
}

I’m not crazy about using a private property, but I couldn’t figure out another way of doing this. That seems like a lack of some API to me. Ordinarily when you’re in properties or observers it’s fine to just deal with the null because you’ll be run again when the promise resolves. In routes, however, you’re at a lower level of abstraction and dealing with promises directly.

So my question is, is there a public API I’m missing to accomplish this? If not, I’d like to propose something along these lines, equivalent to above.

model: function() {
  return this.controllerFor('session').getAsync('user.company');
}