extjsextjs7

Can we avoid setting additional fields in Model?


Ext.define('User', {
  extend: 'Ext.data.Model',
  fields: [
    {name: 'name',  type: 'string'}
  ]
});
Ext.create('User', { 'name' : 'A', 'createdBy': 'Random' });

EXTJS 4.1 ignores 'createdBy' field while creating record. While in 7.4, it saves additional (not configured) fields too.

Output in 7.4

{
  "name": "A",
  "createdBy: "Random"
}

Can we avoid this (having 'createdBy' in data of record) through any configuration?


Solution

  • After going through Release Notes of many versions, I found this.

    Migration Guide - EXTJS 4.2 to 5.0

    It mentions following override, which will restore the behavior of record creation.

    Ext.define('App.overrides.data.Model', {
        override: 'Ext.data.Model',
        constructor: function (data) {
            this.raw = Ext.apply({}, data);
            this.callParent(arguments);
        }
    });
    

    I don't have problem with dynamic field creation, but would have been better if they had introduced it as configurable behavior or give similar fields map to process in writer.