mardi 17 novembre 2015

Ember 2.1.0 (CLI) & Ember Data 2.1.0 'belongsTo' POST to API using EmbeddedRecordsMixin

Using the DS.EmbeddedRecordsMixin Class to POST a new record to API using RESTAdapter.

What am I missing? The 'activity' field in Post is still 'null' - I have tried various implementations but from what can I see the below should work.

serializers/useractivity.js

export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs: {
    activity: { embedded: 'always' }
  }
});

models/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}}

Aucun commentaire:

Enregistrer un commentaire