-
26 May 2012 8:23 AM #1
Model Associations will not work for client proxies
Model Associations will not work for client proxies
I was trying to use model with associations on a flow that only use localstorage and I realized that it is impossible.
HasMany association is forcing filtering remote. You can resolve this by passing in association config store:{remoteFiltering:false} but there is also forced modelDefaults with foreignKey: me.get(primaryKey), and this one is made like this:
So it is practically impossible to use HasMany association with client filtering and you will end having all the records in the associated model updated to have the associated.foreignKey = owner.primaryKey, because of the forced modelDefaultsCode:modelDefaults[foreignKey] = me.get(primaryKey); config = Ext.apply({}, storeConfig, { model : associatedModel, filters : [filter], remoteFilter : true, modelDefaults: modelDefaults });
I guess it should be specified that Association are working only with remote filtering, so with server proxies. (at least by default)
-
26 May 2012 9:54 AM #2
Some fixing (?)
Code:hasMany: { model: 'MyApp.model.Book', autoLoad: true, foreignKey: 'id_author', store: { remoteFilter: true, modelDefaults: false, proxy: { type: 'maskingproxy', maskedStore: 'Books' } } }Code:Ext.define( 'MaskingProxy', { extend:'Ext.data.proxy.LocalStorage', alias:'proxy.maskingproxy', config:{ maskedStore:false, }, read: function(operation, callback, scope) { var filters = operation.getFilters(); var store = Ext.StoreManager.lookup( this.getMaskedStore() ); store.clearFilter(true); store.setFilters(filters); //I know my store is loaded :P var rec = store.getRange(0,store.getCount()-1); operation.setSuccessful(); operation.setCompleted(); operation.setResultSet(Ext.create('Ext.data.ResultSet', { records: rec, total : rec.length, loaded : true })); operation.setRecords(rec); callback.call(scope,operation); } } );


Reply With Quote