PDA

View Full Version : Associated Model not being initialized and Getter not being created Ext.data.Model



darren102
16 Sep 2012, 12:17 PM
Been working with an associated model and trying to get it to load per the Data Package docs but so far can only load the top level model. The raw content has the correct information in it hence i believe i must be doing something wrong in the model definitions hence any information would be appreciated.

BaseModel


Ext.define('Imms.model.BaseModel', {
extend:'Ext.data.Model',


config: {
idProperty:'Id'
},


fields:[
{ name:'Id', type:'string' },
{ name:'__type', type:'string'},
{ name:'IMMSDataModelType', type:'string'}
]
});


ProblemCauseType Model


Ext.define('Imms.model.ProblemCauseType', {
extend:'Imms.model.BaseModel',


fields:[
{ name:'Code', type:'string'},
{ name:'Name', type:'string'}
],


associations:[
{ type:'hasMany', model:'ProblemCause', name:'Causes'}
],


proxy: {
type: 'rest',
url: 'data/problemcausetypes.json',
reader: {
type: 'json'
}
}
});


ProblemCause Model


Ext.define('Imms.model.ProblemCause', {
extend:'Imms.model.BaseModel',


fields:[
{ name:'Code', type:'String'},
{ name:'Name', type:'string'}
],


associations:[
{ type:'belongsTo', model:'ProblemCauseType', name:'CauseType'}
]
});


JSON being loaded into the Models


[
{
"__type":"DTOSerializer:#IMMSDataService.Core.DTO",
"Id":"3e3e374c-0dba-42b9-bc8f-6ff1250a5729",
"Name":"Internal",
"Code":"",
"Causes":[
{
"__type":"DTOSerializer:#IMMSDataService.Core.DTO",
"Id":"c6914a3a-d802-4220-979c-d8d36b2dde46",
"Name":"Software Failure",
"Code":"",
"CauseType":{
"__type":"DTOSerializer:#IMMSDataService.Core.DTO",
"IMMSDataModelType":"ProblemCauseType",
"Id":"3e3e374c-0dba-42b9-bc8f-6ff1250a5729"
},
"IMMSDataModelType":"ProblemCauseDetails"
},
{
"__type":"DTOSerializer:#IMMSDataService.Core.DTO",
"Id":"8f7d5674-0c91-4279-994c-f40568ff6fcb",
"Name":"Hardware Failure",
"Code":"",
"CauseType":{
"__type":"DTOSerializer:#IMMSDataService.Core.DTO",
"IMMSDataModelType":"ProblemCauseType",
"Id":"3e3e374c-0dba-42b9-bc8f-6ff1250a5729"
},
"IMMSDataModelType":"ProblemCauseDetails"
}
],
"IMMSDataModelType":"ProblemCauseTypeDetails"
},
{
"__type":"DTOSerializer:#IMMSDataService.Core.DTO",
"Id":"dc59d21c-5256-4a63-aa9d-a44f53eb2dc5",
"Name":"vl_TestProblemCauseType",
"Code":"",
"Causes":[
{
"__type":"DTOSerializer:#IMMSDataService.Core.DTO",
"Id":"7c70ceff-a001-494f-9179-03f2e4769d8c",
"Name":"vl_TestProblemCause",
"Code":"56789",
"CauseType":{
"__type":"DTOSerializer:#IMMSDataService.Core.DTO",
"IMMSDataModelType":"ProblemCauseType",
"Id":"dc59d21c-5256-4a63-aa9d-a44f53eb2dc5"
},
"IMMSDataModelType":"ProblemCauseDetails"
}
],
"IMMSDataModelType":"ProblemCauseTypeDetails"
}
]


Console output looks like this:



Array[6]


0: constructor

data: Object

Code: ""
IMMSDataModelType: "ProblemCauseTypeDetails"
Id: "36deae12-cef1-4285-8625-239d584bc1fb"
Name: "External"
__type: "DTOSerializer:#IMMSDataService.Core.DTO"
__proto__: Object

dirty: false
events: Object
hasListeners: HasListeners
id: "Imms.model.ProblemCauseType-36deae12-cef1-4285-8625-239d584bc1fb"
index: 0
internalId: "36deae12-cef1-4285-8625-239d584bc1fb"
modified: Object
phantom: false
raw: Object

Causes: Array[4]

0: Object

CauseType: Object
Code: ""
IMMSDataModelType: "ProblemCauseDetails"
Id: "be0611d6-be1d-4121-a983-44c342620286"
Name: "Vandalism"
__type: "DTOSerializer:#IMMSDataService.Core.DTO"
__proto__: Object

1: Object
2: Object
3: Object
length: 4
__proto__: Array[0]

Code: ""
IMMSDataModelType: "ProblemCauseTypeDetails"
Id: "36deae12-cef1-4285-8625-239d584bc1fb"
Name: "External"
__type: "DTOSerializer:#IMMSDataService.Core.DTO"
__proto__: Object

store: constructor
stores: Array[1]
__proto__: TemplateClass

1: constructor
2: constructor
3: constructor
4: constructor
5: constructor

vietits
16 Sep 2012, 6:10 PM
See this: http://www.sencha.com/forum/showthread.php?242665-Associated-Model-and-Getter-not-being-created

darren102
17 Sep 2012, 5:08 AM
Not a bug after all more of a documentation / reading of documentation issue.