PDA

View Full Version : Model association not being created



iamcootis
8 Feb 2014, 11:37 AM
Here is my model. It extends from FlowModel which is a Ext.data.model with a few more fields.



Ext.define('My.model.superflow.flowsettings.FlowParam', {
extend: 'My.model.superflow.FlowModel',
fields: [
{
name: 'type'
},
],


hasMany: [
{model: 'My.model.superflow.flowsettings.Choice', name: 'choice' }
]


});


My Choice model looks like this:



Ext.define('My.model.superflow.flowsettings.Choice', {
extend: 'Ext.data.Model',
fields: [
{
name: 'name',
mapping: '_name'
},
{
name: 'label',
mapping: '#text',
convert: function(v, record){
if(v){
return v;
}
if(record.raw.label){
if(record.raw.label.string){
return Ext.util.Format.trim(record.raw.label.string);
}
}
return '';
}
}


],
belongsTo: 'My.model.superflow.flowsettings.FlowParam'
});


I'm instantiating my FlowParams like this: (obj.enum[i]' is a json object)



obj.enum[i]['type'] ='enum';
var e = Ext.create('My.model.superflow.flowsettings.FlowParam',obj.enum[i]);


when I look at var e, in the raw data it has an array called choice, but it hasn't created a choiceStore.
I have done this with other objects by doing store.loadRawData(obj), but for some reason this isn't working in this instance.

I have tried everything from putting a proxy on my FlowParam model:


proxy: {
type: 'memory',
reader: {
type: 'json'
}
}


to adding an associationKey: 'choice' to my hasMany:

Any suggestion to what I may be doing wrong?

mitchellsimoens
12 Feb 2014, 8:21 AM
Associations have to be loaded through the reader which creating a model instance locally will not run it through the reader. It seems you are trying to create the associations yourself and not really using the associations since you are creating the model yourself.