2

I have two entities with fixtures data: User and Role. When I load a User, it contains one Role. I would like to show the name of the role. Here is relevant code:

App.User = DS.Model.extend({
    name: DS.attr('string'),
    role: DS.belongsTo('App.Role'),
});

App.Role = DS.Model.extend({
    name: DS.attr('string'),
});
App.User.FIXTURES = [{
id:1,
name:'user',
role:1
}];
App.Role.FIXTURES = [{
id:1,
name:'reader',
}]

App.UsersRoute = Ember.Route.extend({
 model: function() {
  return App.User.find();
 }
});

 <script type="text/x-handlebars" data-template-name="users">
           {{#each controller}}
              {{name}} {{role.name}}
           {{/each}}
 </script>

the name of role is not displayed but if I change it to {{role.id}} the id of role is displayed

Cœur
  • 37,241
  • 25
  • 195
  • 267
Misha
  • 828
  • 10
  • 23

1 Answers1

0

i think you may need to add

users: DS.hasMany('App.User')

to the definition of your Role model.

Finn MacCool
  • 808
  • 1
  • 7
  • 12