1. #1
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    7
    Vote Rating
    0
    mford71 is on a distinguished road

      0  

    Default Multiple calls to belongsto assocation getter

    Multiple calls to belongsto assocation getter


    Hi,
    Im sure i'm probably missing something simple here (probably because im brand new to javascript), so apologies in advance....

    Ext-JS 4.07

    This bit of code displays a window with a form in. It calls the getter method of a 'belongsTo' association on the record - 'getDataPackage' because I need the 'carrierId' from the parent object for the form. This code works great first time, but the second time I try and display the window I get the error - 'dataPackage.get is not a function'. I know this is probably because the second time I call the getter it doesnt need to do a read, but im unsure as to how to access the cached dataPackage.

    Code:
        displayEditForm: function(grid, record) {
    
            record.getDataPackage(function(dataPackage, operation) {
    
                var editView = Ext.create('SimManager.view.ui.simcontract.Form', {
                    id: 'editSimContractForm',
                    title: 'Edit Sim Contract',
                    layout: 'fit',
                    modal: true,
                    selectedCarrierId: dataPackage.get('carrierId'),
                    companyStore: this.getStore('Company'),
                    carrierStore: this.getStore('SimCarrier'),
                    dataPackageStore: this.getStore('DataPackage')
                });            
                
                var form = editView.down('form');
                form.loadRecord(record);
                editView.show;
                
            }, this);
        },

    Thanks,

    Mark

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,399
    Vote Rating
    849
    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


    The model instance should be cached onto the record based on the associatedName with 'BelongsToInstance' appended. If the property isn't there then it hasn't been loaded. The getter should automatically see this cached version and return it in the callback function however.
    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
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    7
    Vote Rating
    0
    mford71 is on a distinguished road

      0  

    Default


    Ok so I dont see this model instance on the first call as expected, but I do see it on the second call - SimManager.model.DataPackageBelongsToInstance

    Is this a problem with the namespace stuff - does it not recognise this as being the correct instance?

    Here is the model assocation declaration -
    associations: [
    { type: 'belongsTo', model: 'SimManager.model.DataPackage', getterName: 'getDataPackage', foreignKey: 'dataPackageId' }

Thread Participants: 1

Tags for this Thread