-
25 Jan 2013 12:40 AM #1
Model.setProxy() causes wrong destroy method to be invoked
Model.setProxy() causes wrong destroy method to be invoked
Ext version tested:
- Sencha Touch 2.1.0
- Chrome 24
- html
- Using setProxy() on a model instance which already has a proxy set, causes a TypeError "cannot call method 'getRecords'/'getParams' of undefined.
This is probably because Model.applyProxy() causes Ext.factory() to try to destroy the old proxy instance. But since proxy has a method destroy(operation, callback, scope) it calls that instead, where operation is a required parameter..
- Create a model instance
- set a proxy on the instance via setProxy()
- set another proxy on the model instance via setProxy()
- The second setProxy call will throw an exception
- new proxy was set
- TypeError "cannot call method 'getRecords'/'getParams' of undefined.
Code:store = Ext.getStore(theStoreType); model = Ext.ModelManager.getModel("MyModel"); model.setProxy(store.getProxy());
HELPFUL INFORMATION
An old thread regarding this bug http://www.sencha.com/forum/showthread.php?242558-Changing-proxy-leads-to-calling-the-wrong-destroy-method
Debugging already done:- see above analysis
- not provided
- Ubuntu 11.10
-
25 Jan 2013 9:52 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
This is working for me on 2.1.0
Code:Ext.define('MyModel', { extend : 'Ext.data.Model', config : { fields : ['test'], proxy : { type : 'ajax', url : 'data/json.json' } } }); console.log(MyModel.getProxy().getUrl()); MyModel.setProxy({ type : 'ajax', url : 'data/json2.json' }); console.log(MyModel.getProxy().getUrl());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.
-
28 Jan 2013 12:45 AM #3
Thanks for your answer, and sorry for the very brief "test case" I provided..
However, in my case the current model has no proxy on the first run and that's what causing the "nullpointerexception". This updated example won't work:
Short background: I have implemented the use of a Rest-proxy in a store, using the proxy.rest-docs as a reference. I have defined the rest proxy in my stores and all CRUD operations are working great, except Read. When I want to load a single model instance from the server using the example code (see Ext.data.proxy.Rest docs) I realized that I had to set the proxy on the model too. And it was when I did that I stumbled upon this bug(?).Code:Ext.define('MyModel', { extend : 'Ext.data.Model', config : { fields : ['test'] } }); console.log(MyModel.getProxy().getUrl()); MyModel.setProxy({ type : 'ajax', url : 'data/json2.json' }); console.log(MyModel.getProxy().getUrl());
I'd be grateful for another look at this.
-
30 Jan 2013 7:53 AM #4
Do I have to change the [NOREPRO]-tag to get another look at this, and in that case: how do I change it?
Thanks,
/J
-
15 May 2013 8:04 AM #5
I get this error in Sencha 2.2.0.
Same thing. When I give a model/record the second time the same proxy with record/model.setProxy(X) I get
Uncaught TypeError: Cannot call method 'getParams' of undefined
Is there a way to fix this?
-
15 May 2013 8:25 AM #6
-
15 May 2013 11:48 PM #7
My workaround was to override applyProxy in my Model as follows
Code:applyProxy: function(proxy, currentProxy) { return Ext.factory(proxy, Ext.data.Proxy, null, 'proxy'); }
Looks like we cannot reproduce this. Please provide another test case to reproduce this issue.


Reply With Quote