PDA

View Full Version : Working with ExtJs model associations



anwarmalik
5 Jun 2012, 11:47 PM
I am facing an issue, while implementing model associations. here are my models


Ext.define('EPSS.model.EventType', { extend: 'Ext.data.Model',
uses: [
'EPSS.model.Event'
],


idProperty: 'Id',


fields: [
{
name: 'Id'
},
{
name: 'Name'
},
{
name: 'Color'
},
{
name: 'EventId'
}
]
});

Ext.define('EPSS.model.Event', {
extend: 'Ext.data.Model',
uses: [
'EPSS.model.EventType'
],


idProperty: 'Id',


fields: [
{
name: 'Id'
},
{
name: 'Name'
},
{
name: 'DueDate',
type: 'date'
},
{
name: 'Status'
},
{
name: 'LastModified',
type: 'date'
},
{
name: 'EventTypeId'
}
],
associations: [{
type: 'belongsTo',
model: 'EPSS.model.EventType',
associatedName: 'EventType',
instanceName: 'EventType'
}],


proxy: {
type: 'rest',
url: '/epss/api/Event',
reader: {
type: 'json',
root: 'data'
}
}
});







Here is the json data




{
DueDate: "/Date(1338922800000+0500)/",
EventType: {
Color: "green",
Id: 1,
Name: "Begining of Year"
},
EventTypeId: 1,
Id: 1,
LastModified: "/Date(1275332400000+0500)/",
Name: "Event 1",
Status: "approved"
}


when I execute following line of code...

var row = store.getAt(0);


row.getEventType(function (event) {

}, this);

following exception is thrown

Uncaught TypeError: undefined is not a function

mitchellsimoens
7 Jun 2012, 1:49 PM
You can specify the getterName config to what you want.

anwarmalik
8 Jun 2012, 3:58 AM
still, no luck, I have create a fiddle on the following link for testing

http://jsfiddle.net/9MR7j/3/