Load model and relations with promises


#1

Hey everyone,

I wish to load my model and it’s relationship models before the transition starts using promises.

For simplicity image a simple app consisting of Posts and Comments. How would you load the post and it’s comments with promises? Is the following the right way? If so, is there a way to make this a little more readable?

It seems to work, but in the template I loop over post.comments so I can’t know if the comments are preloaded or not. Is there a way to check this?

Post Route

export default Ember.Route.extend({

  model(params) {
    return this.store.findRecord('post', params.post_id).then((post) => {
      return post.get('comments').then( () => {
        return post;
      });
    });
  }

});

Thanks!