-
27 Mar 2012 5:20 AM #1
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
-
27 Mar 2012 9:15 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
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
________________
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.
-
28 Mar 2012 12:38 AM #3
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' }


Reply With Quote