Search code examples
ember.jsember-data

Iterating over DS.hasMany in Ember data


I have a real struggle with Ember.

In my model I have an attribute:

options: DS.hasMany('UserOptions', {async: false})

In a view linked to this model I can easily access this property by e.g.:

{{#each options AS |option|}}
    something....
{{/each}}

and that works like a charm.

However when I try to access this model value in controller with: this.get('model.options') instead of getting a lovely array of payment options, I get an ember model array of objects, and there's no way I can access the actual data.

Do you guys have any idea how do I access this data in controller and process it?

Thanks!


Solution

  • Below code solved my case:

    @get('model.options').toArray().forEach((item) ->
      console.log(item.get('parameter_name')]
    )
    

    That's true that console.log(@get('model')) was throwing something strange in console, however when I asked for a specific parameter, it was there!

    My problem was that I was trying to print out an entire object instead of a specific value. The values were there, it just didn't print the entire object for a reason.