Hybrid View

    Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-500 in a recent build.
  1. #1
    Ext JS Premium Member
    Join Date
    Apr 2008
    Location
    San Francisco, CA
    Posts
    10
    Vote Rating
    0
    stormin_walker is on a distinguished road

      0  

    Exclamation Can't have more than 1 hasMany association

    Can't have more than 1 hasMany association


    I'm guessing I can have more than 1 hasMany association, but it's not working. I can connect one of the associations (always just the first one defined in the "hasMany" array), but never both.

    It's easy to recreate. If I add the following to the nestedLoading.js example (in KitchenSink) it breaks:

    Code:
    Ext.regModel('User', {
        fields: ['id', 'name'],
        
        hasMany: [{model: 'Order', name: 'orders'},{model: 'Phone', name: 'phones'}],
        
        proxy: {
            type: 'ajax',
            url : 'src/demos/data/userData.json'
        }
    });
    
    Ext.regModel('Phone', {
        fields: ['id', 'number']
    });
    
    Ext.regModel('Order', {
        fields: ['id', 'status'],
        
        hasMany: {model: 'OrderItem', name: 'orderItems'}
    });
    
    Ext.regModel('OrderItem', {
        fields: ['id', 'quantity', 'price', 'name']
    });
    Now just add some phones to the userData.json:

    Code:
    ...
        {
            "id": 1,
            "name": "Ed Spencer",
    	"phones": [{
    		"id": 1,
    		"number": "123456789"
    	}],
            "orders": [
    ...
    Note: when doing this it's just the record for "Ed Spencer" that's broken. So it appears that it's having trouble building the child stores from the JSON.

    (BTW: the Sencha forum has become Japanese - my settings are US English but for some reason everything is Japanese all of a sudden - thankfully Chrome translates the pages for me

  2. #2
    Ext User
    Join Date
    Jul 2010
    Posts
    3
    Vote Rating
    0
    hq242 is on a distinguished road

      0  

    Default


    Hi there,

    I've noticed the same issue. Defining 2 "hasMany" associations in the same model will just get one child store but never both child stores for both "hasMany" associations.

  3. #3
    Ext JS Premium Member
    Join Date
    Jul 2008
    Location
    Miami, FL
    Posts
    51
    Vote Rating
    1
    omarc is on a distinguished road

      0  

    Default


    This might have something to do with it, try changing the readAssociated function in Ext.data.Reader as indicated here:

    Code:
        readAssociated: function(record, data) {
            var associations = record.associations.items,
                length       = associations.length,
                association, associationName, associationData, proxy, reader, store, i;
    
            for (i = 0; i < length; i++) {
                association     = associations[i];
                associationName = association.name;
                associationData = data[association.associationKey || associationName];
    
                if (associationData) {
    //ADD THESE 2 LINES HERE
                    reader = null;
                    proxy = null;
    
                    proxy = association.associatedModel.getProxy();
    
                    // if the associated model has a Reader already, use that
                    if (proxy) {
                        reader = proxy.getReader();
                    }
    See if after doing this change you still have the same problem with more than one hasMany.

    I found this to be a quick fix for having two associations, one a hasMany and the other a belongsTo.

    Let me know if that works for you.

    Omar

  4. #4
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    I've fixed this in Reader.js now and added unit tests to confirm. This will work correctly in the next release. Thanks for you patience while we sorted this out.
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  5. #5
    Ext User
    Join Date
    Oct 2010
    Posts
    4
    Vote Rating
    0
    ShiroiSame is on a distinguished road

      0  

    Default


    Ok but... when the next release?!

    Because I need to fix this now...

    @omarc: your solution works... great!!!

  6. #6
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    Should be Monday 28th. This override should get you by until then - just include it after Sencha Touch but before your application:

    Code:
    Ext.override(Ext.data.Reader, {
        readAssociated: function(record, data) {
            var associations = record.associations.items,
                length       = associations.length,
                association, associationName, associatedModel, associationData, inverseAssociation, proxy, reader, store, i;
            
            for (i = 0; i < length; i++) {
                association     = associations[i];
                associationName = association.name;
                associationData = this.getAssociatedDataRoot(data, association.associationKey || associationName);
                associatedModel = association.associatedModel;
                
                if (associationData) {
                    proxy = associatedModel.proxy;
                    
                    // if the associated model has a Reader already, use that, otherwise attempt to create a sensible one
                    if (proxy) {
                        reader = proxy.getReader();
                    } else {
                        reader = new this.constructor({
                            model: association.associatedName
                        });
                    }
                    
                    if (association.type == 'hasMany') {
                        store = record[associationName]();
                        
                        store.add.apply(store, reader.read(associationData).records);
                        
                        //now that we've added the related records to the hasMany association, set the inverse belongsTo
                        //association on each of them if it exists
                        inverseAssociation = associatedModel.prototype.associations.findBy(function(assoc) {
                            return assoc.type == 'belongsTo' && assoc.associatedName == record.constructor.modelName;
                        });
                        
                        //if the inverse association was found, set it now on each record we've just created
                        if (inverseAssociation) {
                            store.data.each(function(associatedRecord) {
                                associatedRecord[inverseAssociation.instanceName] = record;
                            });                        
                        }
    
                    } else if (association.type == 'belongsTo') {
                        record[association.instanceName] = reader.read([associationData]).records[0];
                    }
                }
            }
        }
    });
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  7. #7
    Sencha User
    Join Date
    Dec 2010
    Posts
    18
    Vote Rating
    1
    Jeff Blake is on a distinguished road

      0  

    Default


    What's the story with this bug? The above solution did not work.

    The weird thing with my case is that if I change the order of the includes for models in the index.html file - it either produces a "property x is undefined"
    If I switch the order of the hasMany models, I get no error but instead no data is able to display from the second model.

    This is a weird issue, any ideas?

  8. #8
    Sencha User
    Join Date
    Aug 2011
    Posts
    17
    Vote Rating
    0
    beetree is on a distinguished road

      0  

    Default


    Quote Originally Posted by stormin_walker View Post
    (BTW: the Sencha forum has become Japanese - my settings are US English but for some reason everything is Japanese all of a sudden - thankfully Chrome translates the pages for me
    Haha, I have the same issue now. I remember seeing you post this before. How did you solve it? Seems like we not only have to fix buggs in the lib but also on the forum

  9. #9
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    @beetree what version are you on?
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  10. #10
    Sencha User
    Join Date
    Sep 2011
    Posts
    7
    Vote Rating
    0
    bk.dbe is on a distinguished road

      0  

    Default Not fixed in Sencha Touch 1.1.0

    Not fixed in Sencha Touch 1.1.0


    Hello all,

    I had the XTemplate + Models associations problem, with Sencha Touch 1.1.0.
    I followed the solution provided in this topic : http://www.sencha.com/forum/showthre...-and-XTemplate

    I hope the next version will be fix (I don't like to use custom patches in production environment).

    Thanks.

Similar Threads

  1. Hint: Models with hasMany in Lists
    By NeoVanGoth in forum Sencha Touch 1.x: Discussion
    Replies: 3
    Last Post: 15 Jul 2011, 5:19 AM
  2. Replies: 12
    Last Post: 19 Jan 2010, 5:36 AM
  3. regarding the EXTJS trees - association/link
    By sravanth in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 5 Jun 2009, 2:30 AM
  4. 1:m association tables
    By johnstontrav in forum Ext 2.x: Help & Discussion
    Replies: 13
    Last Post: 14 May 2008, 3:27 AM

Thread Participants: 12

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar