Supplying two different models to a controller


#1

Hi, I have CourseEnrollmentRoute and CourseEnrollmentController. This basically means I am trying to enroll certain users to a particular course. Thus, this route should have the users as its model. Here is the model hook of CourseEnrollmentRoute

model: function() {
        var users = this.store.find("user"); }

I trainsition to this route, from the courses page, which has a list of courses. Thus I use tranisitionToRoute with the model as the particular course the user clicks on.

enrollCourse: function(params) {
			var course = this.store.find("course", params);
			
			this.transitionToRoute("course.enrollment", course);
		}

Now, in my CourseEnrollmentController, I can only see the Users model and cannot get the course model. I need the course model to fetch the courseid to do a POST.

What is the best way to access both these models in my enrollment controller?


#2

Well you can use setupController on the Route

setupController: function(controller, model) {
  controller.set('model', this.modelFor('notes.show'))
  controller.set('contacts', this.store.find('contact'))
  this._super(controller, model)
}

Here I need both models in my controller.


#3

Thanks. That was exactly what I was looking for.