Saving a record sends the pluralized value for type attribute in PATCH request


#1

I am developing a simple TODO manager application in Ember using ember-data and JSONAPISerializer.

I have the following model which represents a task

app/model/task.js

export default DS.Model.extend({
    title: DS.attr ('string'),
    description: DS.attr ('string'),
    isComplete: DS.attr ('boolean')
});

The corresponding JSON data from back-end looks like this

{
    "data": {
        "id": "1",
        "type": "task",
        "attributes": {
            "title": "Complete Ember TODO manager application",
            "description": "Build a simple Ember application for easily managing tasks",
            "is_complete": "false"
        }
    }
}

I have added editing support for task using the following controller.

app/controllers/tasks/task.js

import Ember from 'ember';

export default Ember.Controller.extend({
    isEditingTask: false,

    actions: {
        startEditTask() {
            this.set('isEditingTask', true);
        },
        doneEditTask(id) {
            this.set('isEditingTask', false);
            this.get('model').save();
        },
    }
});

When not in editing mode, an edit button is shown, which triggers the startEditTask action. When in editing mode a done button is show which triggers the doneEditTask action.

I have verified that the done button does generate a PATCH request.

The problem is that the JSON sent to the back-end has the type as tasks not task. Is this expected?

JSON sent with PATCH request is as follows

{
    "data": {
        "id": "1",
        "type": "tasks",
        "attributes": {
            "title": "Allow editing of a task",
            "description": "Allow the user to change various properties of a task",
            "is_complete": "true",
    }
}

#2

The question was duplicated on stackoverflow, so answered there, maybe it will be useful to somebody else http://stackoverflow.com/a/41730744/4427843