PDA

View Full Version : Missing hasMany associations sending data back to server



salgaf
2 Mar 2015, 8:09 AM
Hi all,
I'm trying to implement REST client that manage CRUD operations with nested JSON model.
Everything il loaded correctly, I can see the store with the associated records.
When I made some change to the data and sync() the nested data are missing from the output JSON.
Below my implementation:



Ext.define('zeroClickProv.model.llfCircuit', {
extend: 'Ext.data.Model',

requires: [
'Ext.data.field.Field'
],

fields: [
{
name: 'Label'
},
{
name: 'LosToCircuit'
},
{
name: 'InsertionMode'
}
]
});

Ext.define('zeroClickProv.model.llfBase', {
extend: 'Ext.data.Model',

requires: [
'Ext.data.field.Field'
],

hasMany: {
model: 'zeroClickProv.model.llfCircuit',
name: 'Circuits',
associationKey: 'Circuits'
},

fields: [
{
name: 'id'
},
{
name: 'EthPhysName'
},
{
name: 'Status'
},
{
name: 'AlarmToCircuit'
},
{
name: 'Delay'
},
{
name: 'ProtMode'
}
]
});

Ext.define('zeroClickProv.view.cardLlfViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.cardllf',

requires: [
'Ext.data.Store',
'Ext.data.proxy.Rest',
'Ext.data.reader.Json',
'Ext.data.writer.Json'
],

stores: {
data: {
autoLoad: false,
autoSync: true,
model: 'zeroClickProv.model.llfBase',
listeners: {
load: 'onJsonstoreLoad'
},
proxy: {
type: 'rest',
url: 'http://MyRestService',
headers: {
accept: 'application/json'
},
reader: {
type: 'json'
},
writer: {
type: 'json',
writeAllFields: true //I need that all data will be send back to server
}
}
}
}

});



Data loaded


[
{
"id": 151,
"Circuits": [
{
"Label": "circ 1",
"LosToCircuit": 1,
"InsertionMode": 1
},
{
"Label": "circ 2",
"LosToCircuit": 1,
"InsertionMode": 0
}
],
"EthPhysName": "test",
"Status": 1,
"AlarmToCircuit": 1,
"Delay": 3,
"ProtMode": 0
}
]


After some changes this is sent to the server when sync()


{
"id": 151,
"EthPhysName": "test",
"Status": 2,
"AlarmToCircuit": 2,
"Delay": 4,
"ProtMode": 0
}

Circuits are gone...

Probably I'm missing some key option or a bad approach to the use case
Thanks in advance to any help

salgaf
3 Mar 2015, 5:01 AM
Bump Can anyone from the sencha dev team please take a look at this issue or anyone who has any input. Thanks.