How to make embedded hasMany relationships work with ember data

On master, the correct API is:

App.Adapter.map('App.Post', {
  comments: { embedded: 'always' }
});

The two possible values of embedded are:

  • load: The child records are embedded when loading, but should be saved as standalone records. In order for this to work, the child records must have an ID.
  • always: The child records are embedded when loading, and are saved embedded in the same record. This, of course, affects the dirtiness of the records (if the child record changes, the adapter will mark the parent record as dirty).

If you don’t have a custom adapter, you can call map directly on DS.RESTAdapter:

DS.RESTAdapter.map('App.Post', {
  comments: { embedded: 'always' }
});

Leave a Comment