PDA

View Full Version : Model Association does not work in case of xml



babar.sajjad
26 Jan 2011, 12:47 PM
i have two models plans and meals with plan hasMany relationship with meals and this is my store

Application.gv.mStore = new Ext.data.Store({
autoLoad: true,
model: "Plan",
proxy: {
type: 'ajax',
url : 'http://localhost/myplan/get_plans/4a6d9721-d0dc-44f5-9429',
reader: {
type: 'xml',
root: 'Plans',
reader: 'Meals'
}
}
});

xml i am consuming is like this


<?xml version="1.0" encoding="utf-8"?>
<nutritions_response>
<response>
<Plans>
<id>123</id>
<name>babar</name>
<Meals>
<item>
<id>456</id>
<name>breakfast</name>
</item>
<item>
<id>456</id>
<name>breakfast</name>
</item>
</Meals>
</Plans>
</response>
</nutritions_response>

my plan object get filled with the data but meal object remains empty if i change reader to item then my plan object is filled with meal data, do not know what to do :(

babar.sajjad
28 Jan 2011, 5:52 AM
at last i made it worked with json but i have a serious question, is it necessary that associated models names are lowercase and plurals :( because it does not work with uppercase and singular names like
This work

{
"plans": [
{
"id": "1195",
"user_id": "1",
"meals": [
{
"id": "6371",
"title": "Breakfast",
"plan_id": "1195"
},
{
"id": "6372",
"title": "Morning Snack",
"plan_id": "1195"
},
{
"id": "6373",
"title": "Lunch",
"plan_id": "1195"
},
{
"id": "6374",
"title": "Snack P.M",
"plan_id": "1195"
},
{
"id": "6375",
"title": "Dinner",
"plan_id": "1195"
},
{
"id": "6376",
"title": "Late Night Snack",
"plan_id": "1195"
}
]
}
]
}
This will not work :(

{
"Plan": [
{
"id": "1195",
"user_id": "1",
"Meal": [
{
"id": "6371",
"title": "Breakfast",
"plan_id": "1195"
},
{
"id": "6372",
"title": "Morning Snack",
"plan_id": "1195"
},
{
"id": "6373",
"title": "Lunch",
"plan_id": "1195"
},
{
"id": "6374",
"title": "Snack P.M",
"plan_id": "1195"
},
{
"id": "6375",
"title": "Dinner",
"plan_id": "1195"
},
{
"id": "6376",
"title": "Late Night Snack",
"plan_id": "1195"
}
]
}
]
}