PDA

View Full Version : I am not getting associations data in Store-> Record ->Data-> Property as collection



vinodpadmanaban@gmail.com
26 Dec 2011, 11:06 AM
hi,

I need one property as collection in a model, so i tried associations but when i look on "records" parameter in store load event, (Store-> Record ->Data ->Array Property) i am getting like "[object Object]", but not as array collection.

when i watch "raw" property in Record, i am getting proper array collection .

I.e

My Code



Ext.define('MyApp.model.user.examModl', {
extend: 'Ext.data.Model',
idProperty :'examId',
hasMany: 'MyApp.model.user.examTypeModl',
proxy:{
type: 'ajax',
api: {
read: 'readExam.htm' //url to read data from db
},
reader: {
type: 'json',
root: 'res',
idProperty: 'examId',
successProperty: 'success',
totalProperty: 'totalCount'
},
writer: {
type: 'json',
encode: true,
root: 'res',
writeAllFields : true
}
},
fields:[{
name: 'examId',
type: 'string'
},
{
name: 'examName',
type: 'string'
},
{
name: 'examTypes',//It shoud be in array
type: 'string' // is there any collection type to be specified ?
}] ,
associations: [
{type: 'hasMany', model: 'MyApp.model.user.examTypeModl', name: 'examTypes'}
]
});

Ext.define('MyApp.model.user.examTypeModl', {
extend: 'Ext.data.Model',
idProperty :'examTypeId',
belongsTo: 'examTypes',
fields:[{
name: 'examTypeId',
type: 'string'
},
{
name: 'examId',
type: 'string'
},
{
name: 'examType',
type: 'string'
},

{ name: 'active',
type: 'bool'

}]
});


My json responce will be :-


{"res":[{"examId":1,"examName":"mathematics","examTypes":[{"examTypeId":1,"examId":"1","examType":"MCQ","active":true}]}],"totalCount":1,"success":true}


In my store load event, when i watch "records" parameter,



records[1].data.examTypes="[object Object]"

as like object , but iam getting in raw property

records[1].raw.examTypes = proper array collection.


i don't know where i am going wrong or any property missing/wrongly assigned.

mitchellsimoens
26 Dec 2011, 5:46 PM
Executing the getter for a hasMany association will return an Ext.data.Store instance.

vinodpadmanaban@gmail.com
28 Dec 2011, 3:12 AM
Hi mitchell,

sorry i don't know how to do "getter", i tried like below, but its not working ,is this right?



Ext.define('MyApp.model.user.examModl', {
fields:[{
name: 'examId',
type: 'string'
},
{
name: 'examName',
type: 'string'
},
{
name: 'examTypes',//It shoud be in array
type: 'string' // is there any collection type to be specified ?
}] ,
associations: [{
type: 'hasMany',
model: 'MyApp.model.user.examTypeModl',
primaryKey: 'examTypeId',
foreignKey: 'examId',
associationKey: 'examTypes'
}]




If not can you provide any example links!!!

I updated the property type(name: 'examTypes', type: 'string') to array now its coming as array field but not as examTypeModl object.