I have a problem about mapping property of model fields.
First, this is my model:
Ext.define('app.model.userModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.Field'
],
idProperty: 'UserId',
fields: [
{
mapping: 'EMAIL',
name: 'UserEmail',
type: 'string'
},
{
mapping: 'ID',
name: 'UserId',
type: 'string'
},
{
mapping: 'NAME',
name: 'Name',
type: 'string'
}
],
proxy: {
api: {
read: readUrl,
create: createUrl,
update: updateUrl,
destroy: destroyUrl
},
type: 'ajax',
reader: {
type: 'json'
},
writer: {
type: 'json',
allowSingle: false,
writeAllFields: true,
nameProperty: 'mapping'
}
}
});
And i have a store like this:
Ext.define('app.store.userStore', {
extend: 'Ext.data.Store',
requires: [
'app.model.userModel',
'Ext.data.proxy.Ajax',
'Ext.data.reader.Json'
],
constructor: function (cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'userStore',
model: 'app.model.userModel',
autoLoad: true,
pageSize: 1,
proxy: {
api: {
read: readUrl,
create: createUrl,
update: updateUrl,
destroy: destroyUrl
},
type: 'ajax',
enablePaging: true,
reader: {
type: 'json',
rootProperty: 'SuccessObjs',
totalProperty: 'Count'
},
writer: {
type: 'json',
allowSingle: false,
writeAllFields: true,
nameProperty: 'mapping'
}
}
}, cfg)]);
}
});
Now, if i use field name of json object directly as model field name, this code works perfectly (without nameProperty: 'mapping' line of writers). But when i map json object field names to something else only mapped names exists in record ( {'UserEmail', 'UserId', 'Name'} ). And if i add nameProperty: 'mapping' line to writers all properties of record are duplicated ( {'EMAIL', 'UserEmail', 'ID', 'UserId', 'NAME', 'Name'} ). This is the problem because when i try to save my record, there are 2 name property in my record and this confuses my backend.
Sorry for the long post, there is no potato here.
Thanks in advance.