PDA

View Full Version : extraParams not returning values on C(R)UD



dawieb
10 Mar 2012, 1:00 PM
I have the following construct (please see below). When I populate my form (using getResults), the POST method provides the extra parameters defined below, but for Update, Create or Destroy the POST method doesn't? See Firebug's output below the construct...

Ext.define('PersonalInfo', {
extend: 'Ext.data.Model',
fields: [{name:'id',type:'int'}, 'name', 'address', 'state'],
proxy: {
type: 'direct',
api: {
create: QueryDatabase.createRecord,
read: QueryDatabase.getResults,
update: QueryDatabase.updateRecords,
destroy: QueryDatabase.destroyRecord
},
extraParams: {
spage: 'testpage',
scomponent: 'grid'
}
}
});

For getResults firebug shows: (note spage and scomponent exist)

{"action":"QueryDatabase","method":"getResults","data":[{"spage":"testpage","scomponent":"grid","page":1,"start":0,"limit":25}],"type":"rpc","tid":1}

For the other CRUD operations it shows (note missing spage and scomponent):
Create:
{"type":"rpc","tid":2,"action":"QueryDatabase","method":"createRecord","result":{"id":20454,"name":"aaa","address":"aaa","state":"aaa"}}

Update:
{"type":"rpc","tid":3,"action":"QueryDatabase","method":"updateRecords","result":{"id":20454,"name":"aaabbb","address":"aaa","state":"aaa"}}

Delete:
{"type":"rpc","tid":4,"action":"QueryDatabase","method":"destroyRecord","result":{"results":null}}


I'm struggling... trying to figure out a clean way to submit extra parameters with all of the CRUD opearations... can anyone please advise?

dedoz
10 Mar 2012, 1:10 PM
from docs
extraParams : Object

Extra parameters that will be included on every read request. Individual requests with params of the same name will override these params when they are in conflict.

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.Direct (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.data.proxy.Direct)
in extraParams description

dawieb
11 Mar 2012, 12:26 AM
Thanks! I read the definition under Proxy, instead of Direct... I'm a newbie...
How else could I send some extra information while doing updates, deletes or inserts? Is there a way?

dawieb
11 Mar 2012, 12:30 AM
I guess I could append it to the Sort parameter and parse the string at the server, but I like keeping things clean as possible... thanks anyhow for any better ideas!

dedoz
11 Mar 2012, 12:48 AM
the only way i know is just to add those params as model fields so they will be sent as any other field,
if those extra params you want to send change on every request just set them before sending

or if they are always the same maybe you can add a field with a conversor and with a mapper which ends in a "computed field" that actually doesnt exists, and that conversor always returns the same value for each record

just ideas to do what your are trying to do

dawieb
11 Mar 2012, 3:02 AM
Great! That could work... I wrote the function to set extra field I added to the model (scomponent), but how do I call this function whenever one of the CRUD operations execute? Thanks for helping!

Ext.define('PersonalInfo', {
extend: 'Ext.data.Model',
fields: [{name:'id',type:'int'}, 'name', 'address', 'state', 'scomponent'],
setExtraParam: function() {
this.set('scomponent', 'grid');
},
proxy: {
type: 'direct',
api: {
create: QueryDatabase.createRecord,
read: QueryDatabase.getResults,
update: QueryDatabase.updateRecords,
destroy: QueryDatabase.destroyRecord
}
}
});

dawieb
11 Mar 2012, 7:31 AM
Ah, I found a clean solution... create field in Model, and use defaultValue...

thanks!