1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    2
    Vote Rating
    0
    nds9619 is on a distinguished road

      0  

    Default Answered: nested model associations cleared after initial load?

    Answered: nested model associations cleared after initial load?


    I've created a custom proxy type for retrieving data from a javascript remoting method that returns an array of objects. The issue is that during autoLoad, the ListStore shows values in the "Contacts" array. However, once I click on a List component bound to this store, the Contacts array for each record is cleared. I suspect is has something to do with

    Code:
            read: function (operation, callback, scope) {             //Here goes your read logic
                HTML5RemoteExtensions.query('Select ID,Name,Type,AccountNumber,Industry,AnnualRevenue,Phone, (Select Id, Name from Contacts) from Account',function handleResponse (result, event) {  //, (Select Id, Name from Contacts)
                    console.log(JSON.stringify(result));                
                    demos.ListStore.loadData(result.records);
                    demos.ListStore.sort('Name', 'ASC');
                    demos.ListStore.loading = false;              
                    demos.ListStore.sync();
                }, {escape:false}
                );     
            },
    And the Model:
    Code:
    Ext.regModel('Account', {    fields: ['Id', 'Name', 'Type', 'AccountNumber', 'Industry', 'AnnualRevenue', 'Phone', 'Contacts'], 
        associations:[
            {type: 'hasMany', model: 'Contact', name: 'Contacts'}
        ],    
        idProperty: 'Id',         
        proxy: {
            type: 'myProxy',
            reader: {
                type: 'json',
                totalProperty: 'totalSize',
                successProperty: 'done',
                root: 'records'
            }  
       } 
    });
    Ext.regModel('Contact', {
        fields: ['Id', 'Name', 'AccountId'],  
        belongsTo: ['Account', {model: 'Account', associationKey: 'AccountId'}],
        idProperty:'Id'
    });
    And the data returned from initial "read":
    Code:
    {"records":[{"Name":"test5","RecordTypeId":"012U0000000KLkCIAW","Type":"first","Id":"001U00000071eXtIAI","Industry":"first"},{"Name":"GenePoint","Phone":"(650) 867-3450","AccountNumber":"CC978213","Type":"second","Contacts":[{"Name":"Edna Frank","AccountId":"001U0000002KPCDIA4","Id":"003U0000001XpgCIAS"}],"Id":"001U0000002KPCDIA4","AnnualRevenue":30000000,"Industry":"Biotechnology"}]}
    And the debug of the ListStore after rendering the list component:
    Code:
    {"Name":"GenePoint","Phone":"(650) 867-3450","AccountNumber":"CC978213","Type":"second","Contacts":[],"Id":"001U0000002KPCDIA4","AnnualRevenue":30000000,"Industry":"Biotechnology"}

  2. Yes, the association is then made so the field is then not there.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,555
    Answers
    3447
    Vote Rating
    814
    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


    Yes, the association is then made so the field is then not there.
    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.

  4. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    2
    Vote Rating
    0
    nds9619 is on a distinguished road

      0  

    Default association not needed?

    association not needed?


    Success. Apparently the Account's association to Contact is not needed when not using the reader?
    Thanks much

    Code:
    Ext.regModel('Account', {    fields: ['Id', 'Name', 'Type', 'AccountNumber', 'Industry', 'AnnualRevenue', 'Phone'], 
        /*associations:[
            {type: 'hasMany', model: 'Contact', name: 'Contacts'}
        ],   */ 
        idProperty: 'Id',         
        proxy: {
            type: 'myProxy',
            reader: {
                type: 'json',
                totalProperty: 'totalSize',
                successProperty: 'done',
                root: 'records'
            }  
       } 
    });
    solved the issue.

Thread Participants: 1

Tags for this Thread