/**
 * Created by dungvn3000 on 3/14/14.
 * The model automatic update mapping field when set associations table.
 */

Ext.define('sunerp.model.BaseModel', {
    extend: 'Ext.data.Model',
    set: function (fieldName, newValue) {
        var me = this;
        Ext.each(me.associations.keys, function (key) {
            if (fieldName == key) {
                Ext.each(newValue.fields.keys, function (field) {
                    me.set(key + "." + field, newValue.get(field))
                });
                me.set(key + 'Id', newValue.get('id'));
            }
        });
        me.callParent(arguments);
    }
});
/**
 * Created by dungvn3000 on 3/14/14.
 * The model automatic update mapping field when set associations table.
 */

Ext.define('sunerp.model.BaseModel', {
    extend: 'Ext.data.Model',
    set: function (fieldName, newValue) {
        var me = this;
        me.callParent(arguments);
        if (newValue != null && Ext.isObject(newValue)) {
            Ext.each(me.associations.keys, function (table) {
                if (fieldName == table) {
                    for (var key in newValue) {
                        me.set(table + "." + key, newValue[key]);
                    }
                    me.set(key + 'Id', newValue.id);
                }
            });
        }
    }
});
Fix nested model should be a value object.
Fix nested model should be a value object.
