You found a bug! We've classified it as EXTJS-8822 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Touch Premium Member pmarko's Avatar
    Join Date
    Dec 2007
    Location
    Ireland
    Posts
    58
    Vote Rating
    1
    pmarko is on a distinguished road

      0  

    Default [4.2.0.555] Ext.data.Model does not load associated data on .save + .copyFrom()

    [4.2.0.555] Ext.data.Model does not load associated data on .save + .copyFrom()


    Hi Folks,

    Ext.data.Model does not load nested associated data when save method is performed because Ext.data.Model.copyFrom method doesn't do deep clone.

    This override fixed it. Tested with hasOne, hasMany, belongsTo associations with phantom and non phantom records.

    PHP Code:

    Ext
    .define('Override.data.Model', {
        
        
    override'Ext.data.Model',
            
         
    copyFrom: function(sourceRecord) {
            
             var 
    me this;
             
             
    me.callParent(arguments);
             
            if (
    sourceRecord) {

                
    // If this is a phantom record being updated from a concrete record, copy the ID in.
                // me.phantom commented out as we always take the server record as the master
                // if it is in use, and associated record has changed on server after update this change
                // will not reflect into our record
                
    if (/*me.phantom && */ !sourceRecord.phantom) {
                    
    // beginEdit to prevent events firing
                    // commit at the end to prevent dirty being set
                    
    me.beginEdit();
                    
    me.setId(sourceRecord.getId());
                    
    me.endEdit(true);
                    
    me.commit(true);
                }
                
          
                
    // association support, took from forum.. don't remember the thread :-(
                // just tested for associations I'm using, works well
                
    for (i=0i<associations.lengthi++) {
                    
    association associations[i];
                    
    instanceName association.instanceName;
                    
    theirs sourceRecord[instanceName];
                    if (
    theirs) {
                        
    mine me[instanceName];
                        if (
    mine) {
                            
    mine.copyFrom(theirs);
                        }
                        else {
                            
    this[instanceName] = theirs;
                        }
                    }
                }
            }
        }
    }); 

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    56
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Thanks for the report! I have opened a bug in our bug tracker.

Thread Participants: 1