JFFortierQc
5 Dec 2011, 8:03 PM
Hi
When we create a new Model, we can set fields that can be mapped to a JSon object. So this said, if we want to set some variables to our model that are used for anything else, can we use fields?
For example :
Ext.regModel('User', {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'},
{name: 'phone', type: 'string', mapping: 'phoneNumber'}
]
});
All those fields can be map to a JSon file. If I want to add a new variable that will hold another Model that need to be instantiated once only, not a Store, only a single var, can we do something like :
Ext.regModel('User', {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'},
{name: 'phone', type: 'string', mapping: 'phoneNumber'},
{name: 'myPersonalVar', type: 'MyModelType'},
]
});
Or what is the best practice. Actually even if I set it as MyModelType, it does not map to the JSon data. I could use a hasMany (Store), but for only one instance I think that it's too much. So, for now I set my var in the fields and its value to 'auto'. Then I create a method that I call to set the Model.
Something like that:
setMyModel: function(myObj) {
this.myPersonalVar = Ext.ModelMgr.create(myObj, 'MyModelType');
}
So, to resume my questions,
1- does fields may be use to hold custom var like other Model?
2- if not, how to set custom vars?
3- is there a better way to create child Model as a single instance, not hasMany?
Thanks for your help on that.
Always looking for best practice.
When we create a new Model, we can set fields that can be mapped to a JSon object. So this said, if we want to set some variables to our model that are used for anything else, can we use fields?
For example :
Ext.regModel('User', {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'},
{name: 'phone', type: 'string', mapping: 'phoneNumber'}
]
});
All those fields can be map to a JSon file. If I want to add a new variable that will hold another Model that need to be instantiated once only, not a Store, only a single var, can we do something like :
Ext.regModel('User', {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'},
{name: 'phone', type: 'string', mapping: 'phoneNumber'},
{name: 'myPersonalVar', type: 'MyModelType'},
]
});
Or what is the best practice. Actually even if I set it as MyModelType, it does not map to the JSon data. I could use a hasMany (Store), but for only one instance I think that it's too much. So, for now I set my var in the fields and its value to 'auto'. Then I create a method that I call to set the Model.
Something like that:
setMyModel: function(myObj) {
this.myPersonalVar = Ext.ModelMgr.create(myObj, 'MyModelType');
}
So, to resume my questions,
1- does fields may be use to hold custom var like other Model?
2- if not, how to set custom vars?
3- is there a better way to create child Model as a single instance, not hasMany?
Thanks for your help on that.
Always looking for best practice.