PDA

View Full Version : filterFn is undefined when using hasMany association



mgogolin
23 Jul 2012, 1:11 PM
I am having an issue when using the hasMany relationship. When loading data into the records in my store, I begin by putting in default values for some of the fields and then make requests to fill in each other field. Because of this I am often using record.set() which works fine for basic data types and hasOne associations. The issue for me occurs when updating the hasMany association. I have to call record.Item().loadRawData() which eventually complains that the filterFn is undefined.

Here is a simplified version of my Model:


Ext.define('MyApp.model.MultiRequestStoreModel', {
extend: 'Ext.data.Model',
idProperty: 'Id',
fields: [
{ name: 'Id', type: 'string' },
{ name: 'RequestsPending', type: 'int' },
{ name: 'RequestsFailed', type: 'int' }
],
associations: [
{ type: 'hasOne', model: 'MyApp.model.Summary', name: 'Summary' },
{ type: 'hasMany', model: 'MyApp.model.Item', name: 'Items' }
]
});

Ext.define('MyApp.model.Summary, {
extend: 'Ext.data.Model',
idProperty: 'Id',
fields: [
{ name: 'Id', type: 'string' },
{ name: 'Name', type: 'string' }
]
);

Ext.define('MyApp.model.Item, {
extend: 'Ext.data.Model',
idProperty: 'Id',
fields: [
{ name: 'Id', type: 'string' },
{ name: 'Name', type: 'string' }
]
);


And here is the store that I am using to load each records parts individually (again simplified)...


Ext.define('MyApp.store.MultiRequestStore', {
extend: 'Ext.data.Store',
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'DetailsStore',
model: ‘MyApp.model.MultiRequestStoreModel’,
loadRecord : function ( record ) {
record.set( 'RequestsPending', 1 );
record.set( 'RequestsFailed', 0 );
Ext.Ajax.request({
url: url,
method: 'GET',
params : params,
scope: this,
success: Ext.bind( function ( response, opts, record ) {
var responseJson = Ext.decode( response.responseText );
record.beginEdit();
record.Items().loadRawData(responseJson);
record.set( 'RequestsPending', record.get('RequestsPending')-1 );
record.endEdit();
this.checkRecordLoaded( record );
}, this, [ record ], true ),
failure: Ext.bind( function ( response, opts, record ) {
record.beginEdit();
record.set( 'RequestsPending', record.get('RequestsPending')-1 );
record.set( 'RequestsFailed', record.get('RequestsFailed')+1 );
record.endEdit();
this.checkRecordLoaded( record );
}, this, [ record ], true )
});
}


It seems that when using hasMany, the store that it creates is contains a filter but the filter is never given a filterFn. This causes an error on ext-all-debug.js line 43576 saying that "fn is undefined". I am using extjs-4.1.0-gpl.

jgitter
12 Oct 2012, 6:24 AM
I'm having this exact same problem... response please?

Dudboi
4 Dec 2012, 9:50 AM
Set


record.Items().remoteFilter = true

before you call loadRawData.