How to make embedded hasMany relationships work with ember data

前端 未结 4 1633
既然无缘
既然无缘 2020-11-27 13:51

I can\'t get embedded hasMany to work correctly with ember data.

I have something like this

App.Post = DS.Model.extend({
          


        
4条回答
  •  野性不改
    2020-11-27 14:32

    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' }
    });
    

提交回复
热议问题