PDA

View Full Version : BUG: REST proxy load instance generate incorrect url



michael.jets
14 Apr 2011, 1:14 AM
Model:


Ext.regModel('Company', {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type : 'string'}],
proxy: {
type: 'rest',
appendId: true,
url : 'http://'+API_SERVER_HOST+'/companies',
format: 'json'
}
});

I have trouble to get resource from server use REST. It is always send request to /companies.json. when I do next:
Ext.ModelMgr.getModel('Company').load(1, {success:function(r){console.log(r.getId())}})

Solution to fix code for RestProxy in method buildUrl:


buildUrl: function()

var records = request.operation.records || [],
record = records[0],
format = this.format,
url = request.url || this.url;

var record_id = (record) ? record.getId() : request.operation.id;
if (this.appendId && record_id) {
if (!url.match(/\/$/)) {
url += '/';
}


url += record_id;
}

if (format) {
if (!url.match(/\.$/)) {
url += '.';
}

url += format;
}

request.url = url;
return Ext.data.RestProxy.superclass.buildUrl.apply(this, arguments);

jsimion
15 Apr 2011, 10:10 AM
This bit me, too. Pretty shocking. If it's in the docs, why is it not in the tests?