dimanche 3 mai 2015

Needs array not working in route (while works in controller)

I have a [needs] rule in several controllers which works something like:

const { computed } = Ember;
export default Ember.Controller.extend({
  needs: ['controller:clients','controller:clients/client'],
  relationship: computed.alias('controllers.clients/client.model'),
  client: computed.alias('relationship.giver'),
}

This allows me to pick up the client ID I need as a parameter to the model function in my "clients.client[:id].sessions" route. It's pretty darn ugly but it completely works in the controller. In the route, however, this almost identical code:

const { computed } = Ember;
export default Ember.Route.extend({
  needs: ['controller:clients','controller:clients/client'],
  relationship: computed.alias('controllers.clients/client.model'),
  client: computed.alias('relationship.giver'),
}

... does not resolve. All of the computed properties are left "undefined". Can anyone help me understand why?

Note: I'd also be happy to incorporate some other way of achieving this same goal in a more compact way ... the pattern I'm solving for is a nested route where a parameter "up the stack" is needed to resolve a model. In my case the client.id is needed as a parameter in the model query for sessions.




Aucun commentaire:

Enregistrer un commentaire