Due to the impact related to this issue, we have to defer this issue to the next major or minor release.
  1. #1
    Sencha User
    Join Date
    Jun 2009
    Posts
    47
    Vote Rating
    0
    curlybracket is on a distinguished road

      0  

    Default Ext.dataview.DataView prepareAssociatedData does not reset index variable j

    Ext.dataview.DataView prepareAssociatedData does not reset index variable j


    The prepareAssociatedData in the dataview prepares the records for rendering the template. If you have more than one association not all referenced records will be converted, because the index variable j used in the inner loop is not reset to zero. You have to add the highlighted statement to preperly iterate over every associated record even if you have more than one association.

    Code:
            prepareAssociatedData: function(record, ids) {            //we keep track of all of the internalIds of the models that we have loaded so far in here
                ids = ids || [];
    
    
                var associations     = record.associations.items,
                    associationCount = associations.length,
                    associationData  = {},
                    i = 0,
                    j = 0,
                    associatedStore, associatedRecords, associatedRecord,
                    associatedRecordCount, association, internalId;
    
    
                for (; i < associationCount; i++) {
                    association = associations[i];
    
    
                    //this is the hasMany store filled with the associated data
                    associatedStore = record[association.storeName];
    
    
                    //we will use this to contain each associated record's data
                    associationData[association.name] = [];
    
    
                    //if it's loaded, put it into the association data
                    if (associatedStore && associatedStore.data.length > 0) {
                        associatedRecords = associatedStore.data.items;
                        associatedRecordCount = associatedRecords.length;
    
    
                        //now we're finally iterating over the records in the association. We do this recursively
                        // FIX: j = 0
                        for (j = 0; j < associatedRecordCount; j++) {
                            associatedRecord = associatedRecords[j];
                            internalId = associatedRecord.internalId;
    
    
                            //when we load the associations for a specific model instance we add it to the set of loaded ids so that
                            //we don't load it twice. If we don't do this, we can fall into endless recursive loading failures.
                            if (ids.indexOf(internalId) == -1) {
                                ids.push(internalId);
    
    
                                associationData[association.name][j] = associatedRecord.data;
                                Ext.apply(associationData[association.name][j], this.prepareAssociatedData(associatedRecord, ids));
                            }
                        }
                    }
                }
    
    
                return associationData;
            }

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,533
    Vote Rating
    871
    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


    I'm going to defer this as the next release looks like there will be changes to the prepareAssociatedData
    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.

Thread Participants: 1