Iterate through hasMany / belongsTo relation in ObjectController

Based on some of the feedback from @alexspeller here, it seems that it might make sense to put those drafts in a separate controller. In your route’s setup controller hook, maybe something like this:

setupController: function(controller, model) {
  controller.set('model', model);
  this.controllerFor('drafts').set('model', model.get('drafts'));
}

Then, your controllers:

App.DraftsController = Ember.ArrayController.extend({
  editable: Em.computed.filterBy('@this', true)
});

App.DocumentController = Ember.ObjectController.extend({
  needs: ['drafts'],
  drafts: Em.computed.alias('controllers.drafts'),
  editableDraft: Em.computed.alias('drafts.editable.firstObject')
});
2 Likes