I have the following two tables:
Table company with this columns:
Table worker with this columns:
The relationship is that one company has many workers
In extjs 4.2 I have this two models:
mdlCompany
Code:
Ext.define('App.model.mdlCompany', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'integer'},
{name: 'name', type: 'string'},
{name: 'cif', type: 'string'},
{name: 'location', type: 'string'}
]
});
mdlWorker
Code:
Ext.define('App.model.mdlWorker', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'integer'},
{name: 'name', type: 'string'},
{name: 'code', type: 'string'}
]
});
How can I set the relations beetween the models? Im trying this line set up in mdlCompany:
Code:
hasMany: {model: 'App.model.mdlWorker', foreignKey: 'idCompany'}
And in mdlWorker:
Code:
{name: 'idCompany', type: 'int'}
Is this the correct way?
The return of the php that gets the data is:
Code:
0:{
id: 1
name: "John",
code: "J001",
company:{
id:1
name: "Company 1",
location: "Some place"}
}
1:{
id: 2
name: "Paul",
code: "P001",
company:{
id:2
name: "Company 2",
location: "Some other place"}
}
...
I have this grid:
Code:
Ext.apply(this, { store: 'somestore with mdlWorker assigned',
stripeRows: true,
loadMask: true,
columns: [
{ text: 'Id', dataIndex: 'id', flex: 1 },
{ text: 'Name', dataIndex: 'name', flex: 1 },
{ text: 'Code', dataIndex: 'code', flex: 1 },
{ text: 'Company', dataIndex: 'company.name', flex: 1 }
],
});
But the column Company is empty when I render the grid
and load its store. Do I need some more configuration? Or How can I
access the company.name property of mdlWorker?