1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    82
    Vote Rating
    1
    Answers
    5
    markevans is on a distinguished road

      0  

    Default Answered: Cannot get simple belongsTo sample code to work?

    Answered: Cannot get simple belongsTo sample code to work?


    I've tried two different examples of a simple belongsTo "getter" and both of them yield the error message "Uncaught Error: [ERROR][Anonymous] You are trying to load a model that doesn't have a Proxy specified"

    One is in the API documentation for "belongsTo".

    The other is a response in a forum thread.

    I posted a question about using this in a list with the "prepareData" config property, but got no response. Now trying to use it in a non-list context. Does it actually work. Can someone point me to a working examples?

    Any other suggestions? Thanks.

  2. Working for me:

    Code:
    Ext.define('Post', {
        extend : 'Ext.data.Model',
    
        config : {
            fields : ['id', 'user_id'],
            proxy  : {
                type   : 'ajax',
                url    : 'data/json.json',
                reader : 'json'
            }
        }
    });
    
    Ext.define('Comment', {
        extend : 'Ext.data.Model',
    
        config : {
            fields    : ['id', 'user_id', 'post_id'],
            belongsTo : 'Post'
        }
    });
    
    Ext.application({
        name   : 'Test',
    
        launch : function () {
    
            var comment = new Comment({
                id      : 1,
                user_id : 1,
                post_id : 1
            });
    
            comment.getPost({
                callback : function (post) {
                    console.log(post);
                }
            });
    
        }
    });
    data/json.json:

    Code:
    {
        "id"      : 1,
        "user_id" : 1
    }

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,714
    Vote Rating
    438
    Answers
    3113
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    Working for me:

    Code:
    Ext.define('Post', {
        extend : 'Ext.data.Model',
    
        config : {
            fields : ['id', 'user_id'],
            proxy  : {
                type   : 'ajax',
                url    : 'data/json.json',
                reader : 'json'
            }
        }
    });
    
    Ext.define('Comment', {
        extend : 'Ext.data.Model',
    
        config : {
            fields    : ['id', 'user_id', 'post_id'],
            belongsTo : 'Post'
        }
    });
    
    Ext.application({
        name   : 'Test',
    
        launch : function () {
    
            var comment = new Comment({
                id      : 1,
                user_id : 1,
                post_id : 1
            });
    
            comment.getPost({
                callback : function (post) {
                    console.log(post);
                }
            });
    
        }
    });
    data/json.json:

    Code:
    {
        "id"      : 1,
        "user_id" : 1
    }
    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.

  4. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    82
    Vote Rating
    1
    Answers
    5
    markevans is on a distinguished road

      0  

    Default


    Thanks for taking the time to try it out. Must be something I'm not doing right. I'll go back and try a few more things.