PDA

View Full Version : BelongsTo association



couetbis
21 Feb 2011, 1:33 AM
Hi,
I want to take place a belongsTo association between 2 models.

I have references and types. In my Reference form, I have a comboBox of types corresponding to Type model.
How to represent this ?



app.models.Reference = Ext.regModel("app.models.Reference", {
fields: [
{name: "id", type: "string"},
{name: "etat", type: "int"},
{name: "description", type: "string"}
],
belongsTo: {
model: 'app.models.TypeMateriel',
foreignKey: 'idType'
},
proxy: {
type: "localstorage",id:'referencestorage'
}
});



app.models.TypeMateriel = Ext.regModel("app.models.TypeMateriel", {
fields: [
{name: "id", type: "int"},
{name: "type", type: "string"}
],
proxy: {
type: "localstorage",id:'typematerielstorage'
}
});


Json is like this :


{
"data": [
{
"id": "RF059863",
"nom": "Inventaire 8",
"nbBureauxScannes": 2,
"nbBureaux": 5,
"bureaux": [
{
"id": "8101",
"etat": false,
"pavancement": 37,
"nbRefTotal": 8,
"nbRefOk": 3,
"nbAnomalies": 1,
"references": [
{
"id": "55370",
"idType": 1,
"etat": 0,
"description": "Lenovo T500,Vista 32bits,4Go mémoire"
}
]
}
]
}
]
}
In console, I have this :

record.data.bureaux[0].references[0]: Object
- app.models.TypeMateriel: Array[0]
- description: "Lenovo T500, Vista 32bits, 4Go mémoire"
- etat: 0
- id: "55370"
- idBureau: "8101"


In others model, I have hasMany association and it works.

I suppose the problem is TypeMateriel isn't load in same json (?)

Any idea ?