3
votes

In my ember app I have a models:

App.Schedule = DS.Model.extend({
    manager:DS.belongsTo('App.Manager', { embedded: true }),
    entries:DS.hasMany('App.Reservation', { embedded: true })
});
App.Reservation = DS.Model.extend({
    name:DS.attr('string')
});

and a handelbars view:

{{#each schedule in controller}}
<td>
  {{#each reservation in schedule.entries)}}
  <div>{{reservation.name}}</div>
  {{/each}}
</td>
{{/each}}

But with this view a've got exception

Expecting 'ID', got 'undefined'

This workaround works, but I know this is wrong way.

{{#each reservation in schedule._data.hasMany.entries}}

Any ideas?

EDIT.

After Mike Aski answer. My JSON, returning from backend.

{
  "schedules": [
    {
      "id": "476a3881-4fe8-42f5-8bdb-650d38f911e8",          
      "entries": [
        {              
          "name": "test1",
          "begin": "2012-11-22T10:00:00+06:00",
          "end": "2012-11-22T11:00:00+06:00",
          "id": "71c6da83-8ae2-4210-90f8-e65b06f819d7"
        },
        {              
          "name": "test2",
          "begin": "2012-11-22T12:00:00+06:00",
          "end": "2012-11-22T14:00:00+06:00",
          "id": "d234c8c0-66f5-4e98-b921-4472b39a98f7"
        }
      ]
    },
    {
      "id": "8d9b1539-8a1f-4a5d-acfc-5918e61e3990",          
      "entries": []
    },
    {
      "id": "a279d9a5-ea88-4012-8094-8a30125fd32b",          
      "entries": []
    }
  ]
}
1
I'm having the same problem except with a recursive relationship (like a tree structure). I've been fighting with Embers hasMany for a while now with no success.Luke

1 Answers

0
votes

Did you ensure you have an id property in the reservations JSON objects?

You should have them, even if relations are embedded.