vendredi 24 novembre 2017

EmberJs: modelFor() returns nothing from parameterized child-route

I have problems getting the parent route-model in a child route with this.modelFor(), because returning undefined in a specific child route.

The routes-structure:

// router.js
....
this.route('backstage', function() {
   this.route('schedules', function() {
      this.route('production', {path: ":production_id"}, function() {
         this.route('develop');
      });
...

in backstage.schedules' route.js:

// route.js
model() {
    return Ember.RSVP.hash({
        productions: this.store.findAll('production'),
    });
},

in backstage.schedules.production's route.js:

model(params) {
    console.log(this.modelFor('backstage.schedules'));  
    // this gives me the correct data for the schedules' model, 
    // hence the productions: {productions: Class}

    return this.store.findRecord('production', params.production_id);
},

and in the template for this route I can access it's model, so it is resolving successfully:

production label:   // prints the production's label

So, it all good till there.
But one level deeper I get the troubles:

in backstage.schedules.production.develop

model() {
    console.log(this.get('routeName')); // backstage.schedules.production.develop
    console.log(this.modelFor('backstage.schedule')); // undefined
    console.log(this.modelFor('backstage.schedule.production'));  // undefined
    return Ember.RSVP.hash({
        production: this.modelFor('production'), 
                 // won't work because it's undefined
                 // I also don't have access to the params of the parent route
    });
},

also in the corresponding template

  // undefined in console
   // reders to [object Object]
  // nothing

I get nothing back.
Could it be, that it's just not possible for dynamic route-models?
Or is there anything I'm doing wrong?

Yes, I know I could get the production in the controller, but I need to setup several other models in the route depending on (beeing filtered by) the production

Infos:
Ember-Cli 2.16
the route in question: http://localhost:4200/backstage/schedules/2/develop




Aucun commentaire:

Enregistrer un commentaire