mardi 30 octobre 2018

Modifying POST url in Ember JS

Can you please explain how to use urlForCreateRecord in adapter to change the post url? I have two model employee and tasks with one to many relationship.

//Employee model
import DS from 'ember-data';

export default DS.Model.extend({
    empId : DS.attr(),
    password : DS.attr(),
    email : DS.attr(),
    tasks : DS.hasMany('task')
});

//Task model
import DS from 'ember-data';

export default DS.Model.extend({
    name : DS.attr(),
    description : DS.attr(),
    startDate : DS.attr(),
    endDate : DS.attr(),
    employee : DS.belongsTo("employee")
});

Now I want to create a task record. I am creating task record like this

let self=this;
let employee=this.store.peekRecord("employee",1);
let task=this.store.createRecord("task",{
    name:self.get("name"),
    description:self.get("description"),
    startDate:self.get("startDate"),
    endDate:self.get("endDate"),
    employee:employee
});
task.save();

The post request should go to URL like /employee/:employee_id/tasks. But the url is getting created like /tasks. How do I achieve the required post url?




Aucun commentaire:

Enregistrer un commentaire