Question

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')
});
Was it helpful?

Solution

you have to pass same data in both cases.(when you get a collection or individual items). I think you are returning partial data in case of collection. When you go through a link it assumes it already has data for that model so it won't send a new request. IMO you should be able to access partial data of that model received in collection.

if the model is big, split it into multiple models. it require server side change also.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top