Results 1 to 3 of 3

Thread: DataView.prepareAssociatedData does not handle belongsTo associations

    Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-1153 in a recent build.
  1. #1
    Sencha User cyberwombat's Avatar
    Join Date
    Oct 2011
    Vote Rating

    Default DataView.prepareAssociatedData does not handle belongsTo associations

    REQUIRED INFORMATIONExt version tested:
    • Sencha Touch 2 PR2
    Browser versions tested against:
    • Chrome 11
    DOCTYPE tested against:
    • HTML
    • The DataView.prepareAssociatedData does not handle loading of belongsTo associations.
    Steps to reproduce the problem:
    • Please view for a full example and description of issue. There is also a semi working method extension listed. That example has Messages with Users. Each message has one user. I load the messages nested with their user in json and want to display the messages as a list with the user data.
    The result that was expected:
    • In my tpl I expected to be able to write {} and have their name show.
    The result that occurs instead:
    • blank name.
    Test Case: has all the code. If the prepareAssociatedData I have in my list is not there it will not work.

    Possible fix:
    • I modified the prepareAssociatedData method based on another posters fix for ST1. From the comments in the method I assume there are other issues which I have yet to encounter. I am not sure if those issues still hold true for ST2 or not as I was not the one to add the comment.
    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];
                    if(association.type === 'belongsTo') {
                        associatedRecord = record[association.associatedName + 'BelongsToInstance'];
                        if(associatedRecord) {
                            associationData[] =;
                            * This does not function as intended. When uncommented items which the record
                            * has many of will only have one item in the result set. However, for now I am
                            * not going to worry about it. Though, I am pretty sure it is important that
                            * this functions properly considering if the record here had yet another
                            * association it would not be loaded into the template. Essentially, at this time
                            * all belongTo associations can be considered leafs, sadly.
                            //Ext.apply(associationData[], this.prepareAssociatedData(associatedRecord, ids));
                    } else {
                        //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[] = [];
                        //if it's loaded, put it into the association data
                        if (associatedStore && > 0) {
                            associatedRecords =;
                            associatedRecordCount = associatedRecords.length;
                            //now we're finally iterating over the records in the association. We do this recursively
                            for (; 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) {
                                    associationData[][j] =;
                                    Ext.apply(associationData[][j], this.prepareAssociatedData(associatedRecord, ids));
                return associationData;

  2. #2
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Redwood City, California
    Vote Rating


    Thank you for the report.

    Sencha Inc

    Jamie Avins


  3. #3
    Sencha User
    Join Date
    Mar 2007
    Haarlem, Netherlands
    Vote Rating


    This has been fixed and will be part of the next Touch 2.0 release. Thanks for the report.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts