Looks like we cannot reproduce this. Please provide another test case to reproduce this issue.
  1. #1
    Ext JS Premium Member
    Join Date
    Feb 2010
    Posts
    28
    Vote Rating
    0
    jlindbergh is on a distinguished road

      0  

    Default 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
    Browser versions tested against:
    • Chrome 24
    DOCTYPE tested against:
    • html
    Description:
    • 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..
    Steps to reproduce the problem:
    • 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
    The result that was expected:
    • new proxy was set
    The result that occurs instead:
    • TypeError "cannot call method 'getRecords'/'getParams' of undefined.
    Test Case:
    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
    Possible fix:
    • not provided
    Operating System:
    • Ubuntu 11.10


  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Ext JS Premium Member
    Join Date
    Feb 2010
    Posts
    28
    Vote Rating
    0
    jlindbergh is on a distinguished road

      0  

    Default


    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:
    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());
    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(?).

    I'd be grateful for another look at this.

  4. #4
    Ext JS Premium Member
    Join Date
    Feb 2010
    Posts
    28
    Vote Rating
    0
    jlindbergh is on a distinguished road

      0  

    Default


    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

  5. #5
    Sencha User
    Join Date
    Aug 2012
    Posts
    10
    Vote Rating
    1
    Vino999 is on a distinguished road

      0  

    Default


    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?

  6. #6
    Sencha User
    Join Date
    Aug 2012
    Posts
    10
    Vote Rating
    1
    Vino999 is on a distinguished road

      0  

    Default


    Quote Originally Posted by Vino999 View Post
    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?
    These guys have all the same problems
    http://www.sencha.com/forum/showthread.php?242558

    http://www.sencha.com/forum/showthread.php?237881-Resetting-store-s-Proxy-from-localStorage-to-AjaxProxy&

    http://www.sencha.com/forum/showthre...oblem&langid=4


  7. #7
    Ext JS Premium Member
    Join Date
    Feb 2010
    Posts
    28
    Vote Rating
    0
    jlindbergh is on a distinguished road

      0  

    Default


    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');
        }

Thread Participants: 2