I'm working in my first web app with Ember.js backed with a Rails for API.
I have the following nested resources:
this.resource('selection_processes', function() {
this.resource('selection_process', { path: '/:selection_process_id' }, function() {
this.resource('candidate', { path: '/candidates/:candidate_id' });
});
})
So, when I access selection_processes/1
it's getting all of its candidates. Thats ok, but the problem is when I click on another selection process link Ember does not perform a new request, rendering no data in my templates. Btw, the API is returning the correct objects.
The only way I got this working was including all objects in my serializers, making Ember getting all the data of the whole nested resources in a single request. But this seems to be a lazy practice and "heavy".
By the way, here are my routes:
Safira.SelectionProcessesRoute = Ember.Route.extend({
model: function () {
return this.store.find('selection_process');
}
});
Safira.SelectionProcessRoute = Ember.Route.extend({
model: function (params) {
return this.store.find('selection_process', params.selection_process_id);
}
});
Safira.CandidateRoute = Ember.Route.extend({
model: function (params) {
return this.store.find('candidate', params.candidate_id);
}
});
UPDATE
Here are my models
Safira.SelectionProcess = DS.Model.extend({
beginDate : DS.attr('date'),
endDate : DS.attr('date'),
title : DS.attr('string'),
description : DS.attr('string'),
steps : DS.hasMany('Safira.Step', {async: true})
});
Safira.Step = DS.Model.extend({
realization: DS.attr('date'),
title: DS.attr('string'),
candidates: DS.hasMany('Safira.Candidate', {async: true}),
selection_process : DS.belongsTo('Safira.SelectionProcess')
});
Safira.Candidate = DS.Model.extend({
name : DS.attr('string'),
email : DS.attr('string'),
confirmation_token : DS.attr('string'),
step : DS.belongsTo('Safira.Step')
});