Is there any possibility to filter the hasMany
records from a model record? I want to get the active projects, grouped by the customer.
Customer
I think the following could work:
controller
Docket.OrganizationProjectsIndexRoute = Docket.AuthenticatedRoute.extend({
setupController: function () {
var projectsController = this.controllerFor('organization.projects');
this.store.find('customer').then(function(customers) {
var promises = customers.map(function(customer) {
return Ember.RSVP.hash({
customer: customer,
projects: customer.get('projects').then(function(projects) {
return projects.filter(function(project) {
return !project.get('archived');
});
});
});
});
Ember.RSVP.all(promises).then(function(filteredProjects) {
projectsController.set('filteredProjects', filteredProjects);
});
});
}
});
template
{{#each filtered in filteredProjects}}
Customer {{filtered.customer}}<br/>
{{#each project in filtered.projects}}
Project {{project.name}}<br/>
{{/each}}
{{/each}}
The trick is use Ember.RSVP.hash to group each customer by active projects.