Is there any way to disable "idProperty" of Model in Extjs?
Asked Answered
D

3

2

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.

Dingbat answered 10/4, 2015 at 13:7 Comment(0)
D
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.

Dogleg answered 17/4, 2015 at 12:46 Comment(0)
B
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'}
    ]
});
Barfuss answered 14/4, 2015 at 15:22 Comment(1)
Thanks, it was close to what I was asking, but @Abdul answer worked exactly for meDingbat
D
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.

Dogleg answered 17/4, 2015 at 12:46 Comment(0)
B
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'
});
Blister answered 10/4, 2015 at 13:35 Comment(4)
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.Dingbat
Your data should not contain the foo value. Checkout the example: fiddle.sencha.com/#fiddle/l4nBlister
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.Dingbat
Maybe you need to change the idParam of the Proxy?Blister

© 2022 - 2024 — McMap. All rights reserved.