Client(Browser) is automatically appending "id" in my JSON which I am sending to server. Here is my model with proxy:
fields: ['id','title','body'],
idProperty: 'id', // this is the default value (for clarity)
// clientIdProperty: 'cliendID',
identifier: 'sequential', // to generate -1, -2 etc on the client
proxy: {
type: 'rest',
//appendId: false,
limitParam:"",
filterParam: "",
startParam:'',
pageParam:'',
url:'http://localhost:3000/posts',
headers: {'Content-Type': "application/json" },
reader: {
type: 'json',
rootProperty:'posts'
},
writer: {
type: 'json'
}
}
When I create a model object to send data to server via Rest, Rest fill the 'id' field with (NameOfMymodel-number).
This is code to create and send model object to server via Rest:
var UserStore = Ext.getStore('peopleStore');
var user = Ext.create('ThemeApp.model.peopleModel',{'title': "Test", 'body': "Testing" });
user.save(); //POST /users
UserStore.load();
Is there any way to stop extjs from appending such id with my data?
This is a similar kind of problem but not what I am looking. how do i prevent an extjs model/proxy from saving the empty primary id on create
Just set persist to false and that's it
Ext.define('ThemeApp.model.peopleModel', {
extend: 'Ext.data.Model',
fields: [ {name: 'id', type: 'int', persist: false},
{name: 'xyz', type: 'auto'}]
}
The 'idProperty' default value is 'id', so simply set persist: false for id property in your model. credits: ajokon (Pointed this in comments by referring to another stackoverflow question)