-
20 Jul 2011 5:56 AM #1
Possible REST proxy bug when record's id is 0
Possible REST proxy bug when record's id is 0
I have a RESTful proxy set up with a Ext.data.Store
When I update a record in that store with id = 1, I get this URL: /productsHandler/1?_dc=..... which is perfect, when when my record's id = 0, I get this URL : /productsHandler/?_dc=... which is incorrect because the id is missing.Code:proxy : { type : 'rest', url : 'productsHandler', reader : { type : 'json', root : 'products' } }
I tried digging around a little bit, and found this, I think this could be the cause:
As you can see, if the id = 0, that bolded "if" statement would evaluate to false. Please take a look at this.Code:buildUrl: function(request) { var me = this, operation = request.operation, records = operation.records || [], record = records[0], format = me.format, url = me.getUrl(request), id = record ? record.getId() : operation.id; if (me.appendId && id) { if (!url.match(/\/$/)) { url += '/'; } url += id; } ......//more code
Thanks
-
22 Jul 2011 9:09 PM #2
Bug confirmed!
REQUIRED INFORMATION
Ext version tested:- Ext 4.0.2a
Browser versions tested against:- Chrome 14.0.825.0 dev-m
- FF5.0

Description:- Rest proxy does not append id to url when loading a model/record with id '0' (as int).
Steps to reproduce the problem:
- Create a Ext.model.Model
- try to load instance with id '0', like MyModel.load(0);
The result that was expected:- a url request to /api/users/0?_dc=..
The result that occurs instead:- a url request to /api/users/?_dc=..
Test Case:
HELPFUL INFORMATIONCode:Ext.require('Ext.ModelManager'); Ext.define('User', { extend: 'Ext.data.Model', fields: ['first', 'last'], proxy: { type: 'rest', url : '/api/users' } }); Ext.onReady(function() { Ext.ModelManager.getModel('User').load(1); // CORRECT: /api/users/1?_dc=.. Ext.ModelManager.getModel('User').load(0); // BUG: /api/users/?_dc=.. // check with Firebug/Developer Tools network tab });
Screenshot or Video:- sure

Debugging already done:- yes
Possible fix:
Additional CSS used:Code:Ext.require('Ext.data.proxy.Rest', function() { Ext.override(Ext.data.proxy.Rest, { buildUrl: function(request) { var me = this, operation = request.operation, records = operation.records || [], record = records[0], format = me.format, url = me.getUrl(request), id = record ? record.getId() : operation.id; if (me.appendId && !Ext.isEmpty(id)) { // FIX if (!url.match(/\/$/)) { url += '/'; } url += id; } if (format) { if (!url.match(/\.$/)) { url += '.'; } url += format; } request.url = url; return me.callParent(arguments); } }); });- -
- Win7
-
24 Jul 2011 11:14 PM #3Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
Awesome, thanks for the report. This is now in the bug tracker. We're performing a series of updates/improvements to data in the next two point releases so expect a lot of progress in that area
Ext JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
You found a bug! We've classified it as
EXTJSIV-3568
.
We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.


Reply With Quote