I have a simple Model/proxy. When I create a object of model to send to server via REST, ExtJs is generating Id and putting its value in my "id" field and that is conflicting with my data.
Is there any way to stop this behavior or to solve this issue?
I have read idProperty Sencha Docs but I am not able to solve my issue. Kindly Help.
Asked
Active
Viewed 2,957 times
2

Adam Gilly
- 49
- 2
- 9
3 Answers
6
Set config options: persist: false
.
Ext.define('User', {
extend: 'Ext.data.Model',
idProperty : 'login'
fields: [
{name: 'login', type: 'string', persist: false},
{name: 'username', type: 'string'},
{name: 'password', type: 'string'}
]
});

ajokn
- 121
- 1
- 5
-
Thanks, it was close to what I was asking, but @Abdul answer worked exactly for me – Adam Gilly Apr 18 '15 at 09:21
3
I ran into same problem and using ajokn answer I did this.
Ext.define('ThemeApp.model.peopleModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int', persist: false},
{name: 'xyz', type: 'auto'}
]
}
I didn't set the idProperty : 'login' cause its default value is 'id', so simply set persist: false for id property in your model.

code4jhon
- 5,725
- 9
- 40
- 60

Abdul Rehman Yawar Khan
- 1,088
- 3
- 17
- 40
1
Set the idProperty to a non existing field. Its dirty I know, but this should do it.
Ext.define('User', {
extend: 'Ext.data.Model',
idProperty : 'foo'
});

Simon Hoss
- 562
- 1
- 3
- 7
-
I have tried this as well, but with this my curd operation start using 'foo' as main 'id' and every time I refresh browser and add data, the previous data is override if a 'foo' value with same number already exist. – Adam Gilly Apr 13 '15 at 09:13
-
Your data should not contain the foo value. Checkout the example: https://fiddle.sencha.com/#fiddle/l4n – Simon Hoss Apr 13 '15 at 10:46
-
yeah things work fine till here. problem occurs when I send data to server and call it back, while sending value of foo will be set and when I call back like Get post/10 client side look for foo's 10 not id 10. – Adam Gilly Apr 13 '15 at 11:23
-
Maybe you need to change the [idParam](http://docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.data.proxy.Ajax-cfg-idParam) of the Proxy? – Simon Hoss Apr 13 '15 at 11:33