extjsextjs4upgradeextjs6extjs-stores

New records get an autogenerated id value. How to get 0 as a new id as in ExtJs 4?


In ExtJs 4, a new record in a store got 0 as an id, before it is synced to the server. In ExtJs 6, the id 'Mb.model.images.Image-1'.

Ext.define('Mb.model.images.Image', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'id', type: 'int'},
        {name: 'code', type: 'string'},
        {name: 'filename', type: 'string'},
        {name: 'path', type: 'string'}
    ]
})

Is it possible to get the old behavior in ExtJs 6 ?

I looked at identifier: 'sequential', but this assigns an autoincrementing id on the client side, which will collide with the server-side assigned id.


Solution

  • No, it is not. The changes in ExtJS 5 around sessions requires all models to have a unique ID.

    You can use the phantom property to see if the model has not ever been saved.

    Furthermore, the Proxy class knows if the model is a phantom, and will issue different calls to the server depending on if the status of the phantom flag (Create operations vs Update operations).

    Any server-side assigned ID will then override the ID of a freshly saved model.