2
votes

Within a controller I am currently doing this:

controller.transitionTo( 'listing', App.Listings.find(1) );

This works just fine. What I would like to know is if there is a way to get access to another controller's model from within a controller so that I do not need to reference 'App.', as this does not seem to be an Ember recommended best practice. I know that there is a modelFor() but it only seems to work in routes.

1

1 Answers

2
votes

Model is set to be the content of the controller, so in your controller the model is the content. (unless you override your controllerFor() method in the route of course).

Then in your controller you should define a needs array, which lists the names of the controller instances (not classes) that you want this controller to have access to.

so for a CommentsController to have access to a PostController you would define it this way, inside your CommentsController definition:

needs: ['post']

Then this is available inside this controller via controllers.post ( you do not need to use model ) if your controller is an instance of ObjectController or ArrayController then you don't even need to worry about going to content, the controller will proxy to the content/model for you.

Note that the comments to post relationship is determined by the router ( specifically how your resources and routes are defined ).

Also, a good starting point for reading up on needs (outside of the source code that is): http://darthdeus.github.com/blog/2013/01/27/controllers-needs-explained/