使用DS.EmbeddedRecordsMixin类使用RESTAdapter将新记录发布到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 action:
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 Post:
{"useractivity":{"activity":null}}
答案 0 :(得分:0)
如下所述,如果任何人有这方面的经验,那么得到答案仍然会很好,因为它应该如上所述。
export default DS.Model.extend({
activity: DS.attr('string'),
activity_details: Ember.computed('activity', function() {
var activity_model = this.get("store").find("activity", this.get('activity'));
return activity_model;
}),
});