Ember dataMany effect

In my ember application, I have 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 handelbars view:

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

But with this view you got an exception

 Expecting 'ID', got 'undefined' 

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

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

Any ideas?

EDIT.

After Mike Asuka's answer. My JSON coming back from the 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": [] } ] } 
+3
source share
1 answer

Have you guaranteed that you have the id property in reservations JSON objects?

You must have them, even if the relationship is rooted.

0
source

Source: https://habr.com/ru/post/1447902/


All Articles