Proper way to access hasMany children from controller

Hello!

I was hoping someone could help me get straight in my mind when I should be treating an ObjectController as a proxy, or going directly to the model.

I have a model Post that hasMany Comments.

In the PostController, should it be:

Ember.ObjectController.extend({
  someFunction: function() {
   var comments = this.get('model.comments');
   // ....... 
  }.property('model.comments.[]')
})

or

Ember.ObjectController.extend({
  someFunction: function() {
   var comments = this.get('comments');
   // ....... 
  }.property('comments.[]')
})

Is there a difference? Why would you use one over the other?

Go with the first way, pointing to model. In Ember 2.0, the proxying controllers, ObjectController and ArrayController will be removed. See https://github.com/emberjs/rfcs/pull/15

3 Likes

Here’s the link to the change made.

https://github.com/emberjs/ember.js/pull/10062#issuecomment-68506660

Thanks! So right now (< 2.0) are they generally equivalent?

Generally. If you use the proxying and you also defined a comments property on your controller in addition to on your post model, it would use that instead.