Ember data: using "references" to the JSON payload for hasMany relationships

For two models, the application uses DS.RESTAdapter :

App.Calendar = DS.Model.extend({ reservations: DS.hasMany("reservation", { async: true }) }); App.Reservation = DS.Model.extend({ date: DS.attr("date"), calendar: DS.belongsTo("calendar") }); 

And useful information, for example:

/ Api / calendar / 1:

 { "calendar": { "id": 1, "reservations": [], "links": { "reservations": "/api/calendar/1/reservations" } } } 

/ Api / calendar / 1 / reservations:

 { "reservations": [ { "id": 1, "date": "10/01/2014" } ] } 

Why is the reservation array in Calendar not loading lazy?

+5
source share
1 answer

Your json should not have reservations set twice

 { "calendar": { "id": 1, "links": { "reservations": "/api/calendar/1/reservations" } } } 
+3
source

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


All Articles