dawesi
13 Aug 2011, 6:49 PM
What's the best way to reuse a model in MVC for a subset without having to redefine the model?
Extension? Plugin?
Hmm... this should be built in functionality (as should remote loader to localstorage)
I'd love to be able to do something like this:
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
{name: 'age', type: 'int'},
{name: 'phone', type: 'string'},
{name: 'gender', type: 'string'},
{name: 'username', type: 'string'},
{name: 'alive', type: 'boolean', defaultValue: true}
],
validations: [
{type: 'presence', field: 'age'},
{type: 'length', field: 'name', min: 2},
{type: 'inclusion', field: 'gender', list: ['Male', 'Female']},
{type: 'exclusion', field: 'username', list: ['Admin', 'Operator']},
{type: 'format', field: 'username', matcher: /([a-z]+)[0-9]{2,3}/}
]
});
Ext.define('User', {
extend : 'Ext.data.SubModel',
model : 'User',
fields : ['name','phone','alive']
});
then the validations and any other related methods, etc would be accessable to the submodel as if it was the original model.
Extension? Plugin?
Hmm... this should be built in functionality (as should remote loader to localstorage)
I'd love to be able to do something like this:
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
{name: 'age', type: 'int'},
{name: 'phone', type: 'string'},
{name: 'gender', type: 'string'},
{name: 'username', type: 'string'},
{name: 'alive', type: 'boolean', defaultValue: true}
],
validations: [
{type: 'presence', field: 'age'},
{type: 'length', field: 'name', min: 2},
{type: 'inclusion', field: 'gender', list: ['Male', 'Female']},
{type: 'exclusion', field: 'username', list: ['Admin', 'Operator']},
{type: 'format', field: 'username', matcher: /([a-z]+)[0-9]{2,3}/}
]
});
Ext.define('User', {
extend : 'Ext.data.SubModel',
model : 'User',
fields : ['name','phone','alive']
});
then the validations and any other related methods, etc would be accessable to the submodel as if it was the original model.