0
使用DS.EmbeddedRecordsMixin類使用RESTAdapter向API發佈新記錄。Ember 2.1.0(CLI)&Ember Data 2.1.0'belongsTo'使用EmbeddedRecordsMixin POST到API
我錯過了什麼? Post中的'activity'字段仍然是'null' - 我嘗試了各種實現,但是從我能看到的下面應該工作。
串行器/ useractivity.js
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
activity: { embedded: 'always' }
}
});
型號/ useractivity.js
export default DS.Model.extend({
activity: DS.belongsTo('activity', { async: true }),
// activity: DS.attr('string'), (using this works fine but I need the link)
});
createRecord行動:
activitysave() {
this.store.createRecord('useractivity', {
activity: 11,
username: "ncole458",
activity_type: "physical",
activity_duration: "06:17:06",
activity_duration_repeats: 1,
activity_duration_weeks: 2,
activity_start: "2015-08-26",
complete_date: null,
activity_checkin: 1,
last_checkin: "2015-09-06",
delete: false,
}).save();
}
API帖子:
{"useractivity":{"activity":null}}