PDA

View Full Version : hasMany association problem



bikgrgphx
23 Jun 2014, 12:45 PM
Hi guys,

i have a problem with associations. I have 2 models (Exercise and Set) which are presented below. I would like to mention that each model has its own store.


Ext.define('Gym.model.Exercise', { extend: 'Ext.data.Model',
requires: [
'Gym.model.Set'
],
config: {
idProperty: 'id',
fields: [
{
name: 'id',
type: 'int'
},
{
name: 'name',
type: 'string'
}
],
hasMany: [
{
model: 'Gym.model.Set',
name: 'sets',
foreignKey: 'exercise_id',
associationKey: 'sets',
primaryKey: 'id',
foreignStore: 'Sets'
}
],
proxy: {
type: 'localstorage',
storeId: 'exercises',
reader: {
type: 'json'
}
}
}
});


Ext.define('Gym.model.Set', { extend: 'Ext.data.Model',
config: {
idProperty: 'id',
fields: [
{
name: 'id',
type: 'int'
},
{
name: 'repetitions',
type: 'int'
},
{
name: 'exercise_id',
type: 'int'
}
],
belongsTo:
{
model: 'Exercise',
foreignKey: 'exercise_id',
name: 'Exercise',
primaryKey: 'id',
foreignStore: 'Exercises'
},
proxy: {
type: 'localstorage',
storeId: 'Sets',
reader: {
type: 'json'
}
}
}
});

First I create a new instance of the model Exercise and some instances of the model Set. Then i assign the instances of the Set model into the instance of Exercise model using the command exercise.sets().add(each instance of set) and in the end i use the commands exercise.sets().sync() and ExercisesStore.sync(). My question is how can i gain access in the children of the model Exercise as the hasMany association doesn't appear anywhere in the browser's localstorage. Screenshot of localstorage is provided below:

49444

Thank you in advance. Any help would be appreciated.