PDA

View Full Version : No store for nested model on parent



ispypie
12 Sep 2011, 4:42 AM
Hi I have two models with an association and a store.



Ext.regModel("App.models.QuestionSet", {
fields: [
{name: "id", type: "string"},
{name: "title", type: "string"},
{name: "text", type: "string"},
{name: "date", type: "string"},
],
hasMany : {associatedModel: 'Question', name: 'questions'}
});

Ext.regModel("App.models.Question", {
fields: [
{name: "id", type: "string"},
{name: "questionSetId", type: "string"},
{name: "title", type: "string"},
{name: "text", type: "string"},
{name: "date", type: "string"},
]
});

Ext.regStore('QuestionSetStore', {
model: 'App.models.QuestionSet',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'data/QuestionSet.json',
reader: {
type: 'json',
root: 'data'
}
}
});


I have the following JSON



{
"success": "true",
"data": [
{
"id": "1",
"title": "Question Set A",
"questions": [
{
"text": "Question 1",
"id": "1"
},
{
"text": "Question 2",
"id": "2"
},
{
"text": "Question 3",
"id": "3"
}
]
}
]
}




If run the code below I was expecting to see a function 'questions' under the QuestionSet instance that would return the nested store for the questions however I do not. Under the raw property of the QuestionSet I can see a questions array with the correct data. Can anyone explain what I should be seeing as I am finding this a bit hit and miss but not entirely sure what I am missing. TIA



var store = Ext.StoreMgr.get('QuestionSetStore');
store.each(function(record) {
console.log(record);
});

edspencer
13 Sep 2011, 10:45 PM
I think you'd have to change your first association to reference the full Model name:



hasMany : {associatedModel: 'App.models.Question', name: 'questions'}