PDA

View Full Version : Issues with XML store with nested data and associations



VDP
7 Aug 2012, 4:54 AM
I have a rather complex XML I want to read into a store. This is my xml




<?xml version="1.0" encoding="UTF-8" ?>
<ws-result success="true">
<ws-data limit="20" rowcount="1" start="0">
<ws-data-row rowid="1">
<lab_visit_id>22</lab_visit_id>
<upddate>02 Feb 2012 14:25:33</upddate>
<lab_id>22</lab_id>
<visit_date>16 Nov 2009</visit_date>
<reason>Inital Visit</reason>
<followup>true</followup>
<reasonfollowup>Check stewardship issues</reasonfollowup>
<comments>Some comments can be in written down in this area</comments>
<attendee_lab
rowcount="1">
<ws-data-row rowid="1">
<lab_visit_contact_id>22</lab_visit_contact_id>
<upddate>02 Feb 2012 14:25:34</upddate>
<lab_visit_id>22</lab_visit_id>
<attendee_id>268</attendee_id>
<first_name>Dora</first_name>
<last_name>Something</last_name>
<email>dorasomething@gmail.com</email>
</ws-data-row>
</attendee_lab>
<attendee_emp rowcount="3">
<ws-data-row rowid="1">
<lab_visit_employee_id>5</lab_visit_employee_id>
<upddate>02 Feb 2012 14:25:34</upddate>
<lab_visit_id>22</lab_visit_id>
<attendee_id>2252</attendee_id>
<first_name>Broke</first_name>
<last_name>Brooker</last_name>
<email>broke.brooker@domain.com</email>
</ws-data-row>
<ws-data-row rowid="2">
<lab_visit_employee_id>6</lab_visit_employee_id>
<upddate>02 Feb 2012 14:25:34</upddate>
<lab_visit_id>22</lab_visit_id>
<attendee_id>50</attendee_id>
<first_name>John</first_name>
<last_name>Smit</last_name>
<email>john.smit@domain.com</email>
</ws-data-row>
<ws-data-row rowid="3">
<lab_visit_employee_id>7</lab_visit_employee_id>
<upddate>02 Feb 2012 14:25:34</upddate>
<lab_visit_id>22</lab_visit_id>
<attendee_id>876</attendee_id>
<first_name>Sandra</first_name>
<last_name>Panda</last_name>
<email>sandra.panda@domain.com</email>
</ws-data-row>
</attendee_emp>
<document rowcount="2">
<ws-data-row rowid="1">
<document_id>600783</document_id>
<document_name>filename1.doc</document_name>
<document_mimetype>application/msword</document_mimetype>
</ws-data-row>
<ws-data-row rowid="2">
<document_id>600784</document_id>
<document_name>filename2.pdf</document_name>
<document_mimetype>application/pdf</document_mimetype>
</ws-data-row>
</document>
</ws-data-row>
</ws-data>
</ws-result>



So I have a model LabVisit and 2 other: Document and Attendee

LabVisit has to have a attendeeLabStore, a attendeeEmpStore (both attendee model) and a documentStore (document model obviously)

Attendee model




Ext.define('AppName.model.subfolder.Attendee', {
extend: 'Ext.data.Model',


fields: [
{
mapping: 'attendee_id',
name: 'AttendeeID'
},
{
mapping: 'first_name',
name: 'firstName'
},
{
mapping: 'last_name',
name: 'lastName'
},
{
name: 'email'
}
]
});




document model




Ext.define('AppName.model.subfolder.Document', {
extend: 'Ext.data.Model',


fields: [
{
mapping: 'document_id',
name: 'docID'
},
{
mapping: 'document_name',
name: 'docName'
},
{
mapping: 'document_mimetype',
name: 'mimeType'
},
{
name: 'uploadID'
}
]
});







Ext.define('AppName.model.subfolder.LabVisit', {
extend: 'Ext.data.Model', requires: [
'AppName.model.subfolder.Attendee',
'AppName.model.subfolder.Document'
],



idProperty: 'labVisitID',


fields: [
{
mapping: 'lab_visit_id',
name: 'labVisitID',
type: 'int'
},
{
mapping: 'lab_id',
name: 'labID',
type: 'int'
},
{
mapping: 'visit_date',
name: 'visitDate',
type: 'date'
},
{
mapping: 'reason',
name: 'visitReason',
type: 'string'
},
{
mapping: 'followup',
name: 'followupNeeded',
type: 'boolean'
},
{
mapping: 'reasonfollowup',
name: 'followupReason',
type: 'string'
},
{
mapping: 'box',
name: 'streetBox'
},
{
mapping: 'comments',
name: 'comments'
},
{
name: 'upddate'
}


],
hasMany: [{
model: 'AppName.store.subfolder.Attendee',
name: 'attendeeLabStore',
associationKey: 'attendee_lab',
reader: {
//root: 'attendee_lab', //I've tried with and without the root properties
record: 'ws-data-row'
}
},{
model: 'AppName.store.subfolder.Attendee',
name: 'attendeeEmpStore',
associationKey: 'attendee_emp',
autoLoad: true,
reader: {
//root: 'attendee_emp',
record: 'ws-data-row'
}
},{
model: 'AppName.store.subfolder.Document',
name: 'documentStore',
associationKey: 'document',
reader: {
//root: 'document',
record: 'ws-data-row'
}
}]
});


Last but not least the store




Ext.define('AppName.store.subfolder.LabVisit', {
extend: 'Ext.data.Store',
requires: [
'AppName.model.subfolder.LabVisit'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'LabVisitStore',
model: 'AppName.model.subfolder.LabVisit',
remoteSort: true,
proxy: {
type: 'ajax',
api: {
read: 'http://localhost/AppName/mockData/getVisitList-action.xml'
},
reader: {
type: 'xml',
idProperty: '@rowid',
successProperty: '@success',
totalProperty: 'ws-data/@rowcount',
record: 'ws-data/ws-data-row'
}
},
sorters: {
property: 'firstName'
}
}, cfg)]);
}
});



But it doesn't work at all. The normal data is getting loaded (like LabVisit's comments, followupNeeded, followupReason,...) the "sub-stores" just aren't there (attendeeLabStore, attendeeEmpStore, documentStore)

And there are 2 new stores inside the element:
- store; containing a LabVisitStore
- stores; containing an array containing 1 element being a LabVisitStore

Anyone a clue what's up?

Here's a screenshot of the most part of the data inside the store.

37781