PDA

View Full Version : Multiple models associations problem



ivan.marquez
25 Mar 2011, 3:48 PM
Hi:
I can only get surveys and categories with following code, but i need to get form info:

this.store = new Ext.data.JsonStore({
autoLoad: true,
model: 'Survey',
proxy: {
type : 'ajax',
url : 'app/stores/json/surveys/index/',
reader : {
type: 'json',
root: 'surveys'
}
}
});

Ext.regModel("Survey", {
fields: [
{name: "id", type: "int"},
{name: "name", type: "string"},
{name: "subtitle", type: "string"},
{name: "link", type: "string"},
{name: "description", type: "string"},
{name: "sort", type: "int"},
{name: "active", type: "int"},
{name: "voting_option", type: "int"},
{name: "email_confirmation", type: "int"},
{name: "image", type: "array"},
{name: "intro_text", type: "string"}
],
hasMany: {model: 'Category', name: 'categories'}
});

Ext.regModel("Category", {
fields: [
{name: "id", type: "int"},
{name: "name", type: "string"},
{name: "subtitle", type: "string"},
{name: "description", type: "string"},
{name: "sort", type: "int"},
{name: "active", type: "int"},
{name: "image", type: "string"}
],
belongsTo: 'Survey',
hasMany: {model: 'Form', name: 'forms'}
});

Ext.regModel("Form", {
fields: [
{name: "id", type: "int"},
{name: "name", type: "string"},
{name: "description", type: "string"}
],
belongsTo: 'Category'
});

JSON RESPONSE:
{
"surveys":[
{
"id":"2",
"name":"Los Angeles Times Readers\u2019 Choice 2011 Best of Southern California",
"subtitle":"",
"link":"http:\/\/survey-latimes.wehaaserver.com\/survey-2-los_angeles_times_readers'_choice_2011_best_of_southern_california.html",
"description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse urna erat, consectetur sed sollicitudin a, molestie at nulla. Nunc bibendum dui sit amet augue pharetra varius. Donec volutpat, magna sit amet laoreet tempor, dui libero pharetra nisl, vel cursus elit lacus id erat. Praesent id nisi nisi, non facilisis felis. Aenean tortor justo, congue nec gravida non, malesuada id quam. Etiam luctus congue orci et adipiscing. Suspendisse vel leo eu ipsum eleifend lacinia ac vitae arcu. Etiam elementum suscipit massa nec tempor. Aenean ullamcorper luctus sapien in tincidunt. Suspendisse sit amet est metus, ultricies eleifend turpis. In feugiat volutpat nunc a viverra.<br>",
"sort":"1",
"active":"1",
"voting_option":"1",
"email_confirmation":"0",
"image":{
"nr":"<img />",
"nal":"<img />",
"nar":"<img />",
"small":"<img />",
"t1":"<img />",
"t2":"<img />",
"t3":"<img />",
"widea":"<img />",
"wideb":"<img />"
},
"intro_text":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse urna erat, consectetur sed sollicitudin a, molestie at nulla. Nunc bibendum dui sit amet augue pharetra varius. Donec volutpat, magna sit amet laoreet tempor, dui libero pharetra nisl, vel cursus elit lacus id erat. ",
"categories":[
{
"id":"2",
"name":"Education",
"subtitle":"",
"description":"",
"sort":"0",
"active":"1",
"forms":[
{
"id":"2",
"name":"Education",
"description":""
}
]
},
{
"id":"3",
"name":"Food & Drink",
"subtitle":"",
"description":"",
"sort":"1",
"active":"1",
"forms":[
{
"id":"3",
"name":"Food & Drink",
"description":""
}
]
},
{
"id":"4",
"name":"Lyfestyle & Entertainment",
"subtitle":"",
"description":"",
"sort":"2",
"active":"1",
"forms":[
{
"id":"4",
"name":"Lyfestyle & Entertainment",
"description":""
}
]
},
{
"id":"5",
"name":"Shopping",
"subtitle":"",
"description":"",
"sort":"3",
"active":"1",
"forms":[
{
"id":"5",
"name":"Shopping",
"description":""
}
]
},
{
"id":"6",
"name":"Services",
"subtitle":"",
"description":"",
"sort":"4",
"active":"1",
"forms":[
{
"id":"6",
"name":"Services",
"description":""
}
]
}
]
}
]
}