1. #1
    Sencha Premium Member
    Join Date
    Dec 2013
    Posts
    11
    Vote Rating
    0
    theSenchaNoob is on a distinguished road

      0  

    Default Having problems with getters/setters generated by Associations

    Having problems with getters/setters generated by Associations


    I'm having trouble trying to invoke getters/setters on a Model object that has an association with one other model. Here are the classes:

    Category.js
    Code:
    Ext.define('Chapter05.model.Category', {
        extend: 'Ext.data.Model',
        fields: [
            { name: 'id',   type: 'int' },
            { name: 'name', type: 'string' }
        ]
    })

    Product.js

    Code:
    Ext.define('Chapter05.model.Product', {
        extend: 'Ext.data.Model',
        
        fields: [
            { name: 'id',          type: 'int' },
            { name: 'category_id', type: 'int' },
            { name: 'name',        type: 'string' }
        ],
        // we can use the belongsTo shortcut on the model to create a belongsTo association
        associations: [
            { type: 'belongsTo', model: 'Chapter05.model.Category' }
        ]
    })

    Main.js

    Code:
    Ext.define('Chapter05.view.Main', {
        extend: 'Ext.container.Container',
        requires:[
            'Ext.tab.Panel',
            'Chapter05.model.Product',
            'Chapter05.model.Category',
        ],
        
        xtype: 'app-main',
        layout: 'vbox',
    
    
        items: [
            {
                xtype: 'button',
                text: 'Category',
    
    
                handler: function(evt) {
                    var product = new Chapter05.model.Product({
                        id: 100,
                        category_id: 20,
                        name: 'Sneakers'
                    });
    
    
                    product.getCategory(function(category, operation) {
                        // do something with the category object
                        alert(category.get('id')); // alerts 20
                    }, this);
                }
            }
        ]
    });

    The error occurs at the line where product.getCategory(...) is. I get the following message in Safari Web Inspector:


    Code:
    TypeError: 'undefined' is not a function (evaluating 'product.getCategory')
    Am I forgetting to do something?

    P.S. The project(Chapter05) was generated using Sencha Cmd. Hence, the fully qualified names.

  2. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    4,913
    Vote Rating
    179
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      0  

    Default


    You may need to set the getterName in the belongsTo config explicitly:
    http://docs.sencha.com/extjs/4.2.2/#...cfg-getterName
    Are you a Sencha products veteran who has wondered what it might be like to work at Sencha? If so, please reach out to our recruiting manager: sheryl@sencha.com

    C
    heck out all of the 2013 SenchaCon presentations here:
    http://www.sencha.com/blog/senchacon...now-available/

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi