PDA

View Full Version : model, hasMany, update all items in a single request



Scott-1
12 Feb 2014, 1:11 PM
I have a model that has an associations


Ext.define('Test.model.Header', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
{name: 'id', type: 'int', convert: null },
{name: 'bankAccount', type: 'string', convert: null },
{name: 'active', type: 'boolean',convert: null, defaultValue: true }
],
associations: [
{
type: 'hasMany',
model: 'Test.model.GridItem',
name: 'gridItems',
foriegnKey : 'id'
}
],
proxy: {
type: 'rest',
api: {
create : 'testData/save',
read : 'testData/get',
update : 'testData/save',
destroy : undefined
}});


Ext.define('Test.model.GridItem', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
{name: 'id', type: 'int', convert: null },
{name: 'firstName', type: 'string', convert: null },
{name: 'lastName', type: 'string', convert: null },
{name: 'active', type: 'boolean',convert: null, defaultValue: false }
]
});


when I update the model I want to update any children in the same request call.
The JSON would look something like this


{ id:1,
bankCode: 'Test',
active: true,
gridItems :
{ id:1, firstName: 'John', lastName : 'Doe', active: true },
{ id:2, firstName: 'Jane', lastName : 'Doe', active: true },
{ id:3, firstName: 'Johnny', lastName : 'Doe', active: true }
}



I can set the header as dirty even if the header did not change, but I want it to go all as 1 transaction so it either all succeeds, or all fails, server side.
Ideally I would like to indicate whether the item is
U for update, D for deleted, A for Added something like the following

{ id:1, firstName: 'John', lastName : 'Doe, active: true, action: 'U' },
{ id:2, firstName: 'Jane', lastName : 'Doe, active: true, action: 'D' },
{ id: , firstName: 'Johnny', lastName : 'Doe, active: true, action: 'A' }

Any ideas.

scottmartin
12 Feb 2014, 1:53 PM
The current writer does not support updating of associated data. You would need to send this info in extraParams or separately and have the server take care of it.