1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    25
    Vote Rating
    0
    invalidoyt is on a distinguished road

      0  

    Default Answered: Synchronous association call or something

    Answered: Synchronous association call or something


    Hello all,

    Is it possible to make use of associations without making a new call to server? When I try to record.getBelongsToModelName(), i need to run a callback to get the data returned and use it. However, I think the models should be able to prepare the data for the store with the associated data.

    Code:
    userrecord.getCompany(function(company) {
    //make use of company
    });
    instead, I spent some time to accomplish something like this:

    Code:
    var mycompany;
    
    mycompany = userrecord.getCompany(function(company) {
         return company;
    });
    of course, it failed as it waited for the server return. then I tried:

    Code:
    var me = this;
    var mycompany;
    
    userrecord.getCompany(function(company) {
         mycompany = company;
    }, me);
    and this:

    Code:
    var me = this;
    var mycompany;
    
    userrecord.getCompany(function(company) {
         me.mycompany = company;
    }, me);
    I also tried other methods that I saw in forum posts:

    Code:
    console.log(userrecord.houses()); //has no method, also tried many name conventions
    So....

    Is there any synchronous way to get the associated model/data? Should I attach the associated data to the child model by defining a "load" callback?

  2. It depends on how much data you load from the server, if you load your parent model... if you have nested data, the associations are filled and you can access these by using yourParentModel.assocName() (giving you a store to the association). If you haven't nested data and want the associations to be lazy loaded, the association stores are there, but not yet filled - so yourParentModel.assocName().load() would load those data and if you need to do something with this loaded data you have to make a callback on success... synchronous wouldn't work there...

    if the store to the association is correctly built, you can also access it with .assocNameStore on your model, which is somehow easier in doing console-debugging stuff...

  3. #2
    Sencha User
    Join Date
    Feb 2010
    Posts
    125
    Vote Rating
    3
    Answers
    7
    börn is on a distinguished road

      0  

    Default


    It depends on how much data you load from the server, if you load your parent model... if you have nested data, the associations are filled and you can access these by using yourParentModel.assocName() (giving you a store to the association). If you haven't nested data and want the associations to be lazy loaded, the association stores are there, but not yet filled - so yourParentModel.assocName().load() would load those data and if you need to do something with this loaded data you have to make a callback on success... synchronous wouldn't work there...

    if the store to the association is correctly built, you can also access it with .assocNameStore on your model, which is somehow easier in doing console-debugging stuff...

  4. #3
    Sencha User
    Join Date
    May 2011
    Posts
    25
    Vote Rating
    0
    invalidoyt is on a distinguished road

      0  

    Default


    Thank you for your answer. I wrapped my code inside the callback function for now due to time issues; in the next one, I will try the methods you recommended...

Thread Participants: 1

Tags for this Thread