Pregunta

Let's assume there are such routes:

  @resource 'group', path: '/group/:group_id', ->
    @route 'tweets'

Now I have these paths and controllers:

  1. group - here I have model loaded by its id
  2. group.index - here I use that model
  3. group.tweets - here I need to load some additional collection that depends on group.id

Naive way to do so (which is not working) in GroupTweetsRoute:

  model: ->
    @store.find 'tweet',
      group_id: @get('controllers.group.id')
      tolerance: @get('controllers.group.membership.tolerance')

I tried controllerFor as well. So at the moment I have no group there. But I see it later or if I get there from the group.index page.

My guess is that there is some async promise-based stuff I can do in beforeModel callback to wait until group is loaded. But what exactly?

¿Fue útil?

Solución

modelFor can be used during the model resolution stage. All of your models are resolved before the controllers are built and set up (which is why your controllerFor wouldn't work in your deeper model hook).

var group = this.modelFor('group'),
    id = group.get('id'),
    tolerance = group.get('membership.tolerance');

Otros consejos

Ok, here is the solution that works in my case:

  model: ->
    @store.find 'tweet',
      group_id: @modelFor('group').get('id')
      tolerance: @modelFor('group').get('membership.tolerance')
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top