Results 1 to 3 of 3

Thread: Multiple calls to belongsto assocation getter

  1. #1
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    7
    Vote Rating
    0
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    7
    Vote Rating
    0
      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' }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •