jeudi 25 août 2016

How to change a belongs to attribute of a model in controller

In my Ember application using ember-data and JSONAPISerializer, I have a task model and a priority model. A task belongs to a priority and a priority can have many tasks associated with it.

The models are as follows

app/model/task.js

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

app/models/priority.js

export default DS.Model.extend({
    title: DS.attr ('string'),
    description: DS.attr ('string'),
    tasks: DS.hasMany ('task'),
});

The user can edit the task and change any attribute including its priority. This is handled in the controller.

The editing form has a dropdown from which the priority can be selected. This drop down is populated by the controller by querying the store.

I have got the editing and saving part to work for all attributes except the priority. I am not able to make the changed priority stick when saving the task.

How to change the priority before saving the model?




Aucun commentaire:

Enregistrer un commentaire