-
22 Mar 2012 12:27 PM #1
[4.1-RC1] Model load method wont use configured idProperty
[4.1-RC1] Model load method wont use configured idProperty
i think this bug has been posted before, but is still there so here goes again.
Ext version tested:
ExtJs 4.1 beta 1, beta 2 , beta 3, RC1
Browser versions tested against:
Firefox 10.0.2
Chrome 17.0.963.66
Description:
Model load static method will always send a request with a field with name "id" and wont use the configured model idProperty.
Steps to reproduce the problem:
Define a simple model with a configured idProperty
Run Model.load()
check the http request data
The result that was expected:
send the configured idProperty name and value to the server
The result that was expected:
always sends a value under the key "id"
Test Case:
also getter (associated record) have the same problem, because they use the the same load methodCode:// just setting a provider to give you full code to test // doenst need to configure anything else // select method doesnt need to exists in the server side, the problem happens when sending Ext.direct.Manager.addProvider({ "url":"php\/router.php", "type":"remoting", "actions":{ "testQuery":[ {"name":"personSelect","len":1} ] } }); Ext.define('Person', { extend: 'Ext.data.Model', fields: [ {name:'someId' , type:'int'} ], idProperty: 'someId', proxy: { type: 'direct', api:{ read : testQuery.personSelect } } }); Person.load(45,{callback: function(record) {}}); // results in // sends this {"action":"testQuery","method":"personSelect","data":[{"id":45}],"type":"rpc","tid":1} // check the "id":45 // should be // "someId":45
can check this just adding a belongsTo association and run getSomething(), and check the request
it doesnt need to be a belongsTo to the same model, just doing this to show less code
but at the end is the same problem, because getter uses Model.Load static method.Code:... code same provider ... Ext.define('Person', { extend: 'Ext.data.Model', fields: [ {name:'someId' , type:'int'}, {name:'parentId' , type:'int'} ], belongsTo : [ {model: 'Person', foreignKey:'parentId', getterName : 'getParent'} ], idProperty: 'someId', proxy: { type: 'direct', api:{ read : testQuery.personSelect } } }); var p = Ext.create('Person',{ someId : 1, parentId : 3 }) p.getParent(); // sends this {"action":"testQuery","method":"personSelect","data":[{"id":3}],"type":"rpc","tid":1} // check the "id":3 // should be // "someId":3
Source of problem
one part seems to come from src/data/model
seems like the id from argments its always passed in a id key, not using the idPropertyCode:Ext.define('Ext.data.Model',{ ........ inheritableStatics: { ........ load: function(id, config) { ........ config = Ext.applyIf(config, { action: 'read', id : id }); ........ } } });
tested to change that to the current configured idProperty
doing
this actually set "someId" : 45 and sends it to the reader but then goin to the reader seems like he always expect an id config property,Code:var cfg = { action : 'read' } cfg[this.prototype.idProperty] = id; config = Ext.applyIf(config, cfg);
because doing this the request now looks like
{"action":"testQuery","method":"personSelect","data":[{}],"type":"rpc","tid":1}
i guess reader didnt find the key "id" in the config.
so dunno but theres the problem i think.
-
22 Mar 2012 1:51 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
This looks to be the same issue as : http://www.sencha.com/forum/showthread.php?152511
Can you confirm?Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
22 Mar 2012 3:49 PM #3
Thank you for reporting this bug. We will make it our priority to review this report.


Reply With Quote