Ember Data: Using "links" on JSON payload for hasMany relationships

Given two models in an app using 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 payloads such as:

/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 it that the reservations array on the Calendar model isn't being lazy-loaded?

Upvotes: 5

Views: 1010

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

Your json shouldn't have reservations defined twice

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

Upvotes: 3

Related Questions