Ember Data - Saving record loses has many relationships

后端 未结 4 1000
栀梦
栀梦 2020-12-28 18:38

I am having an issue working with Ember Data Fixture Adapter. When saving a record, all of the record\'s hasMany associations are lost. I have created a simple JS Bin to ill

4条回答
  •  伪装坚强ぢ
    2020-12-28 19:17

    This is not a bug, rather a design choice in Ember Data.

    The JSONSerializer.serializeHasMany method doesn't serialize manyToOne by design; typically foreign key are persisted on the belongsTo side of the relation, and the hasOne may not persist a foreign key

    A work around is explained in this post: http://www.toptal.com/emberjs/a-thorough-guide-to-ember-data see the section "One-to-many and Many-to-one Relationships" the hack is To force DS.hasMany IDs to be serialized as well, you can use the Embedded Records Mixin. like so attrs: {someRelationship: {serialize: 'ids'}}

提交回复
热议问题