1

I've got a blog-post-editor.

The blog-post I'm editing is the model. Now I'd need all categories for the blog-post stored in a select-box.

What's the best way to retrieve and display those categories?

Currently I'd do it like this in the controller but they are about to be deprecated in Ember 2.0:

categories: function() {
  return this.get('store').find('category');
}.property()
Hedge
  • 16,142
  • 42
  • 141
  • 246
  • categories: function() { return this.store.all('category'); }.property('model') – Swati Feb 21 '15 at 11:14
  • This way I'd have all categories in the model but the model is already occupied by the current post I'm editing. – Hedge Feb 21 '15 at 13:10
  • the above code you need to add in controller.. the model(editing post) you will get from the route.. as according to convention, we get model from the route and the extra things you can get from controller.. so just add it in controller.. am not fully aware of your requirement, so it will be great if you can more details so that i could help you. Thanks. – Swati Feb 21 '15 at 16:47

1 Answers1

1

In your blog-posts route, you can override setupController(controller, model) to retrieve the categories and set them as a property on your controller, e.g.:

App.BlogPostsRoute = Ember.Route.extend({
  setupController: function (controller, model) {
    this._super(controller, model);
    controller.set('categories', this.store.find('category'));
  }
});