mardi 26 mai 2015

Model object not preserved when using hash for model in ember route

Been trying to resolve this for a while now and I'm clearly not understanding how the relationship between model and setupController works. I have a model which is returning a hash; the result of two find calls:

model(params) {
  return Ember.RSVP.hash({
    course: this.store.find('course', params.course_id),
    topics: this.store.find('topic', { course_id: params.course_id })
  });
},

The first time setupController gets called, the value of model if as expected, a hash like { course: Class, topics: Class }. Awesome, that's what I want.

However, the next time setupController gets called (for example, transition to another route and then press the back button in the browser), the model is now just the course Class:

setupController(controller, model) {
    // when first called model will be { course: Class, topics: Class }
    // next time entered, model will just be Class (just the value of "course" )
    // why is the model object not preserved?
   controller.set('model', model.course);
   controller.set('topics', model.topics);
}}

If I just make model() return a single resource, it's the same every time:

model(params) { return this.store.find('course', params.course_id); }
// now `model` will always be "course" in setupController

Why is the original model not preserved when using a hash result? Am I doing something wrong?




Aucun commentaire:

Enregistrer un commentaire