SetupController or Model


#1

If my route only uses a parent model as data, would I return it using the model hook (ie with modelFor(‘parentModel’)) or by setting it with setupController()?

               model(params) {
        		var plannerData = this.modelFor('planner');
        		return plannerData;
        	},

OR

setupController(controller) {
	var plannerData = this.modelFor('planner');
	controller.set('model', plannerData);
}

#2

setupController() method sets a model value for a controller by default. So logically it’s more correct to get a model value via model() and do not override setupController() with super() in case you extend the route from another one where setupController() is already defined and does some extra job / or this route might be extended in the future to get another model just to redefine its model().


#3

Definitely better to use the model hook for this.

If you’re just trying to get your parent route’s model and make it your model, that’s the default behavior, so you don’ t need any model() or setupController() methods at all.


#4

Completely didn’t realise this. Ben deletes code

I find I have a pattern whereby I have a parent route model and in the child models I keep returning a HASH with the parent model in the HASH as key-value.

Like this:

var parentModel = this.modelFor(‘parentModel’); Ember.RSVP.hash({ parentModel:parentModel, childdata2:childdata2, childroutedata2:childroutedata2 } );

It means as I go further down I have more outer containers for the models and more outer containers.

It feels wrong, and I have a feeling there is a better way to pass the data to the controller. Do you know of it