Proper way to access hasMany children from controller


#1

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?


#2

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

Here’s the link to the change made.


#4

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


#5

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.