How do I get a collection of objects using Ember ArrayController?

I can't get the collection of awards with what I am currently doing, what am I doing wrong in choosing this collection?

I keep getting the following error:

Error: Error processing route: Rewards Assertion failed: ArrayController is awaiting model

to implement the Ember.Array mixin. This can often be fixed by wrapping your model with `Ember.A ()

... ->
  # Contests
  @resource 'contests'
  @resource 'contest', { path: '/contests/:contest_id' }

  # Awards
  @resource 'awards', { path: '/contests/:contest_id/awards' }
  @resource 'award', { path: '/contests/:contest_id/awards/:award_id' }

  # Ads
  @resource 'ads', { path: '/contests/:contest_id/ads' }
  @resource 'ad', { path: '/contests/:contest_id/ads/:ad_id' }


`import DS from 'ember-data'`

AwardModel = DS.Model.extend
  # Attributes
  description: DS.attr 'string'
  amount: DS.attr 'string'
  adId: DS.attr 'string'
  adType: DS.attr 'string'
  state: DS.attr 'string'
  thumbnail: ""

  # Relationships
  ad: DS.belongsTo 'ad', async: true
  contest: DS.belongsTo 'contest', async: true

`export default AwardModel` model

`import DS from 'ember-data'`

ContestModel = DS.Model.extend
  # Attributes
  title:          DS.attr 'string'
  truncatedTitle: DS.attr 'string'
  state:          DS.attr 'string'
  totalAwards:    DS.attr 'string'
  totalAds:       DS.attr 'string'
  startsOn:       DS.attr 'date'
  endsOn:         DS.attr 'string'
  daysLeft:       DS.attr 'string'
  thumbnail:      DS.attr 'string'
  createdAt:      DS.attr 'date'

  # Relationships
  ads:    DS.hasMany 'ad',    async: true
  awards: DS.hasMany 'award', async: true

`export default ContestModel` controller

`import Ember from 'ember'`

AwardsController = Ember.ArrayController.extend
  videoAwards: '',
  printAwards: '',

  setAwards: (type) ->
    awards = @filter((award) ->
      award.get('adType') == type.capitalize()
    @set(type + 'Awards', awards)

    sortAwardsByType: ->
      # TODO: find out why this is not working
      # ['video', 'print'].forEach (type) ->
        # @setAwards(type)

`export default AwardsController` route file

`import Ember from 'ember'`
`import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin'`
AwardsRoute = Ember.Route.extend AuthenticatedRouteMixin,
  model: ->
    # How to fetch the awards of the given contest here with ember data
  setupController: (controller, model) ->
    controller.set('model', model)
`export default AwardsRoute`



source to share

1 answer

This will work:

// awards route
model: (params) ->
  @store.find('contest', params.contest_id).then((contest) ->


More on the promises chain here .

Then you can implement filtering on the model in the reward controller.



All Articles