dojodstore

How to create a new record in a dstore using dmodel


I assign a model to a store then call

var model = Store.create({id:0,firstName:"john",lastName:"smith",department:"sales"});
model.save();

This sends a PUT request. Shouldn't it send a POST? I tried not including the id field but then it throws a validation error. Any ideas what I am doing wrong?


Solution

  • It looks like you can not send any id and have it POST. The best way to do this then is either

    var model = Store.create({firstName: "john", lastName: "smith", department: "sales"}); 
    Store.add(model);
    

    or

    var model = new MyModel({firstName: "john", lastName: "smith", department: "sales"}); 
    Store.add(model);