Moving from MVC to MVVM and struggling with view model data associations in store. I have spent a few days reading everything I can but there are no clear examples.


Data as been changed to protect the innocence
Code:
{
  "ITEMS": [
    {
      "site_id": "1",
      "site_name": "xxxxxx",
      "active": "1",
      "master_root_path": "/ASSETS/xxxxxx/",
      "site_backup_plugin": "xxxxxxxxx",
      "mail_id": "1",
      "disk_space_used": "0",
      "INSTANCES": [
        {
          "instance_id": "1",
          "instance_name": "xxxxxxx",
          "active": "0",
          "instance_root_path": "xxxxxxxx",
          "media_valet_server_url": "xxxxxxx",
          "media_valet_api_server_url": "xxxxx"
        }
      ]
    },
    {
      "site_id": "2",
      "site_name": "xxxxxxxxx",
      "active": "1",
      "master_root_path": "xxxxxx",
      "site_backup_plugin": "xxxxxxxx",
      "mail_id": "1",
      "disk_space_used": "272G",
      "INSTANCES": [
        {
          "instance_id": "2",
          "instance_name": "xxxxxx",
          "active": "1",
          "instance_root_path": "xxxxxxxx/",
          "media_valet_server_url": "xxxxxxx",
          "media_valet_api_server_url": "xxxx"
        },
        {
          "instance_id": "3",
          "instance_name": "xxxxxx",
          "active": "1",
          "instance_root_path": "xxxxxxxx",
          "media_valet_server_url": "xxxxxx",
          "media_valet_api_server_url": "xxxxx"
        },
        {
          "instance_id": "4",
          "instance_name": "xxxxx",
          "active": "1",
          "instance_root_path": "xxxx",
          "media_valet_server_url": "xxxxx",
          "media_valet_api_server_url": "xxxxx"
        }
      ]
    }
  ],
  "SUCCESS": true,
  "ERROR_MESSAGE": ""
}
My store/model and associations are set up correctly if I dump the store data to the console on load it show my data and my INSTANCES associations correctly

This is my view model, please note currentSiteInfoRecord and currentMailInfoRecord are working correctly in my view, when I select a site or a mail server from the combo box the other fields fill out correctly

What I want to do, when the site info combo box is changed, which correctly returns the record, I want to get the INSTANCES associations for that record.

I have tried many methods, the method below for backUpInstance but I get an error in the console on load as the current currentSiteInfoRecord is null

Code:
Ext.define('xxxxxx.view.forms.SiteInfoFormModel', {
    extend: 'Ext.app.ViewModel',
    alias: 'viewmodel.siteinfoform',






    stores: {
        SiteInfo: {
            type:'siteinfo',
            autoLoad: true
        },
        MailInfo: {
            type:'mailinfo',
            autoLoad: true
        }
    },
    formulas: {
        currentSiteInfoRecord: {
            bind: {
                bindTo: '{siteInfoComboBox.selection}', //--> reference configurated on the combobox view (reference: siteInfoComboBox)
                deep: true
            },
            get: function(record) {
                return record;
            },
            set: function(record) {
                if (!record.isModel) {
                    record = this.get('records').getById(record);
                }
                this.set('currentSiteInfoRecord', record);
            }
        },
        backUpInstance: {
            bind: {
                bindTo: '{currentSiteInfoRecord}',
                deep: true
            },
            get: function(record) {
                return record.getInstances();
            },
            set: function(record) {
                if (!record.isModel) {
                    record = this.get('records').getById(record).getInstances();
                }
                this.set('backUpInstance', record);
            }


        },
        currentMailInfoRecord: {
            bind: {
                bindTo: '{mailInfoComboBox.selection}', //--> reference configurated on the combobox view (reference: siteInfoComboBox)
                deep: true
            },
            get: function(record) {
                return record;
            },
            set: function(record) {
                if (!record.isModel) {
                    record = this.get('records').getById(record);
                }
                this.set('currentMailInfoRecord', record);
            }
        }


    }
        
});
How to you correctly assign the association of a record to a say a grid or combo box store

Thanks

Harry