Reputation: 361
I'm happy that multiple models can be loaded into a route using something like this (although feel free to correct if there's a better way!):
model: function() {
var self = this;
return Ember.RSVP.hash({
foos: self.store.find('foos'),
bars: self.store.find('bars'),
});
However, if the model hook is set by a model being passed by, for example, a link-to helper, how should I add the additional model?
Thanks!
EDIT
So in my case I have a unit and objective, which are related. A unit can have many objectives - although its a one way relationship.
In my units route, I click on a unit which links-to units/unit:ID route. So the unit is set as the model, but I also want all objectives loaded into the model, so that I can select and add these to the unit.
Upvotes: 0
Views: 53
Reputation: 6947
Not everything in your page must be in the route's model
. For example, you may have a Route
that contains a Unit
object. To get a list of all Objective
objects, you could add a simple property to your controller
:
allObjectives: function() {
return this.store.find('objective');
}.property()
Your template could then render the model as usual:
<div>Unit name: {{model.name}}</div>
<div>All objectives:
<ul>
{{#each objective in allObjectives}}
<li>{{objective.name}}</li>
{{/each}}
</ul>
Upvotes: 1