I am trying to create a simple ExtJS5 app against a Restful RubyonRails backend. For some reason when I instantiate a model ExtJs populates the "idProperty" field with the name of the model (and counter). e.g.
{"Traffic_id":"MyApp.model.Person-1","external_id":0,...
I thought the "idProperty" field is essentially the primary key of the data record and is normally set when the record is inserted in to the DB (autoincrement)
So this field should be null or similar as the model has yet to be added to the store and syncd to the backend.
Whats even more amaising is that the field is defined as 'int' and ExtJS puts a String in it!
Can someone tell me what is going on?
Peter
Below is an app.js to Fiddle with:
Ext.application({
name : 'Fiddle',
launch : function() {
var model = Ext.create('MyApp.model.Person');
Ext.Msg.alert('Fiddle', JSON.stringify(model.data));
}
});
Ext.define('MyApp.model.Person', {
extend: 'Ext.data.Model',
idProperty: 'Traffic_id',
proxy: {
type: 'rest',
// url: '/traffics.json',
format: 'json',
api: {
create: 'traffics',
read: 'traffics',
update: 'traffics/edit',
destroy: 'traffics'
},
reader: {
type: 'json',
rootProperty: 'traffic',
successProperty: 'success',
messageProperty: 'message'
},
writer: {
type: 'json',
//writeAllFields : false,
//encode: true,
rootProperty: 'traffic'
},
afterRequest: function(req, res) {
console.log("Ahoy!", req.operation.response);
},
listeners: {
exception: function(proxy, response, operation) {
//debugger;
Ext.MessageBox.show({
title: 'XXX REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
},
fields: [{
name: 'Traffic_id',
type: 'int'
}, {
name: 'external_id',
type: 'int'
}, {
name: 'description',
type: 'string'
}, {
name: 'insertUser',
type: 'string'
}, {
name: 'insertDate',
type: 'date'
}]
});