Aric
Aric

Reputation: 1397

Emberjs Displaying Associative Data Within Parent Model Template

I've hit a snag in my Ember application that I've been trying to break free from. I have a two models like below:

App.UserModel = DS.Model.extend({
  ../
  actions: DS.hasMany('action')
});

and

App.ActionModel = DS.Model.extend({
  ../
  user: DS.belongsTo('user')
});

My route for viewing a user profile is as follows:

App.UsersProfileRoute = Em.Route.extend({
  model: function(params) {
    return this.get('store').find('user', params.user_id);
  }
});

Which grabs the following structure from the server:

{
  user: {
    action_ids: [1, 2, 3]
  },
  actions: [{
    id: 1,
    type: "Problem"
  },{
    id: 2,
    type: "Problem"
  },{
    id: 3,
    type: "Problem"
  }]
}

This loads up the store properly according to Ember's Chrome Extension. However when I try and access the association data in a template like so:

<h2>Actions</h2>
<div class="container">
  {{#each actions}}
    you have action
  {{else}}
    You don't have actions
  {{/each}}
</div>

It appears that the actions association is empty or null as it doesn't pass the #each check even with the Ember Store showing the proper stored information.

I've tried a few things with the template like {{#each action in model.actions}} etc, but to no avail. Any help would be appreciated!

Upvotes: 0

Views: 93

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

user: {
  action_ids: [1, 2, 3]
},

should be

user: {
  actions: [1, 2, 3]
},

Upvotes: 1

Related Questions