PDA

View Full Version : [CLOSED] Use a field other than 'id' for server calls?



rfox
27 Oct 2011, 10:45 AM
Apologies if this has been asked before its hard to search for :(

Given a model/store with a defined and working proxy, how do i configure it so it does not submit server calls using id.

For example say i have a server side file representing Cars eg(data/cars.json) and i want to load car 3:

model.load(3,success...fail...etc

Firebug always shows my browser as requesting data/cars.json?id=3.

What if i wanted it to use 'carid' eg data/cars.json?carid=3?

Is this possible? I've looked into using the idProperty field in a model but it is either ignored or that's not what it actually does.

I believe what i want is similar to the mapping property that you can define in a writer except for reading.

JambaFun
27 Oct 2011, 4:08 PM
Hi rfox,

This one is so ugly that I'm not even sure I want to post it, but close inspection of Ext.data.Model, Ext.data.proxy.Server and Ext.data.proxy.Ajax only gave one possible solution:

model.load(false, {
params: {carid: 3}
});

Best Regards

rfox
27 Oct 2011, 4:21 PM
That's really anoying, id is a reserved cgi variable in both POST and GET for the server side software im using. Pretty much everywhere I want to load data I cannot use ID as its parameter.

The definition of idProperty on the docs is also confusing :(. Looks like it only affects the internal storage of the model.

Thanks for your input :)

mitchellsimoens
28 Oct 2011, 6:47 AM
I have moved this to the bugs forum and entered as a bug as the idProperty should change the parameter that is sent back. This isn't a bug per-say but an improvement.

rfox
31 Oct 2011, 6:47 AM
Thanks for moving it to bugs its good to know its been acknowledged :)

ldonofrio
31 Oct 2011, 3:24 PM
same problem here, loose 1 day trying to override this and nothing:-?

VDP
26 Aug 2013, 3:55 AM
good one @JambaFun => use undefined instead of false and the id param won't be sent.

My solution is based on your idea:


Ext.define('MyApp.model.MyModel', {
extend: 'Ext.data.Model',

idProperty: 'code',
fields: [
{
name: 'code'
},
{
name: 'version',
type: 'int'
},
{
name: 'content'
}
],
proxy: {
type: 'ajax',
api: {
read: BCS.API_URLS.preference.load,
update: BCS.API_URLS.preference.save,
create: BCS.API_URLS.preference.save
},
reader: {
type: 'json',
root: 'rows',
messageProperty: 'message'
}
}
}, function(model){


var parentLoad = model.load;

model.load = function(id, config) {
config.params = config.params || {};
config.params[model.prototype.idProperty] = id;
Ext.callback(parentLoad, this, [undefined, config]);
};


});