Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-6306 in a recent build.
  1. #1
    Sencha User
    Join Date
    Jun 2011
    Location
    Warsaw, Poland
    Posts
    38
    Vote Rating
    1
    sasklacz is on a distinguished road

      0  

    Default Model's Id field not defined after sync in TreeStore (CRUD)

    Model's Id field not defined after sync in TreeStore (CRUD)


    When using TreeStore I'm adding two parent nodes with two child nodes. For the time of appending nodes, store has autoSync suspended. After syncing the store, in both 'beforesync' and 'write' records have 'Id' field undefined. This is due to a comparison performed in commitRecords :

    Code:
    serverRec = mc.findBy(me.matchClientRec, clientRec);
    which matches record from the server with record in the store and always returns null, as the values being compared are internalId's of both. This is always false, as record returned by the server has internalId already set to some id generated on the server side. The outcome is that record ends up with undefined Id. All works fine when just a single record is added, because then this comparison is skipped.
    We're using patch sent from sencha :

    Code:
            commitRecords: function (serverRecords) {
                var me = this,
                    mc, index, clientRecords, serverRec, clientRec,
                    oldId, newId;
    
    
                if (!me.actionSkipSyncRe.test(me.action)) {
                    clientRecords = me.getRecords();
                    
                    if (clientRecords && clientRecords.length) {
                        if (clientRecords.length > 1) {
                            // if this operation has multiple records, client records need to be matched up with server records
                            // so that any data returned from the server can be updated in the client records.
                            mc = new Ext.util.MixedCollection();
                            mc.addAll(serverRecords);
    
    
                            for (index = clientRecords.length; index--; ) {
                                clientRec = clientRecords[index];
                                serverRec = mc.findBy(me.matchClientRec, clientRec);
    
    
                                // Replace client record data with server record data
                                oldId = clientRec.getId();
                                clientRec.copyFrom(serverRec);
                                newId = clientRec.getId();
                                if (oldId !== newId) {
                                    clientRec.fireEvent('idchanged', clientRec, oldId, newId);
                                }
                            }
                        } else {
                            // operation only has one record, so just match the first client record up with the first server record
                            clientRec = clientRecords[0];
                            serverRec = serverRecords[0];
                            // if the client record is not a phantom, make sure the ids match before replacing the client data with server data.
                            if(serverRec && (clientRec.phantom || clientRec.getId() === serverRec.getId())) {
                                oldId = clientRec.getId();
                                clientRec.copyFrom(serverRec);
                                newId = clientRec.getId();
                                if (oldId !== newId) {
                                    clientRec.fireEvent('idchanged', clientRec, oldId, newId);
                                }
                            }
                        }
    
    
                        if (me.actionCommitRecordsRe.test(me.action)) {
                            for (index = clientRecords.length; index--; ) {
                                clientRecords[index].commit();
                            }
                        }
                    }
                }
            }
    Simplest solution is to just match records by their indexes, but not we're not sure if both length's will always be the same :

    Code:
    serverRec = serverRecords[index];
    Is this a bug or are we doing something wrong? I'm attaching full Siesta test case.
    Attached Files
    Using ExtGantt / ExtScheduler from Bryntum ? I can help you integrate and implement it.

  2. #2
    Sencha - Community Support Team mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    2,777
    Vote Rating
    112
    mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all

      0  

    Default


    Simplified vanilla test case

    Code:
    Ext.require([
        'Ext.data.*',
        'Ext.grid.*',
        'Ext.tree.*'
    ]);
    
    Ext.onReady(function() {
        Ext.define('Task', {
            extend: 'Ext.data.Model',
            idProperty : 'id',
            fields: [
                {name: 'id',     type: 'int'},
                {name: 'task',     type: 'string'},
                {name: 'duration', type: 'string'}
            ]
        });
    
        var store = Ext.create('Ext.data.TreeStore', {
            model: 'Task',
            proxy: {
                type: 'ajax',
                //the store will get the content from the .json file
                actionMethods : { read : 'GET', create : 'GET' },
                api : { create : 'treegrid.json', read : 'treegrid.json' }
            },
            root : {
            }
        });
    
        var one = new Task({ task : 'foo', duration : 20 });
        var two = new Task({ task : 'foo2', duration : 200 });
        store.getRootNode().appendChild(one)
        store.getRootNode().appendChild(two)
        
        store.on('write', function() {
            console.log(store.getById(1) ? 'YUP' : 'CRAP');
        });
        store.sync();
    
    });
    treegrid.json

    Code:
    [
        {
            id : 1,
    		task:'Project: Shopping',
            duration:13.25
    	},
    	{
            id : 2,
            task:'Project: Shopping',
            duration:13.25
    	}
    ]

  3. #3
    Sencha - Community Support Team mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    2,777
    Vote Rating
    112
    mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all

      0  

    Default


    Still some strange stuff going on with 'parentId' value.

    Code:
    Ext.require([
        'Ext.data.*',
        'Ext.grid.*',
        'Ext.tree.*'
    ]);
    
    Ext.onReady(function() {
        Ext.define('Task', {
            extend: 'Ext.data.Model',
            idProperty : 'id',
            fields: [
                {name: 'id',     type: 'int'},
                {name: 'task',     type: 'string'},
                {name: 'duration', type: 'string'}
            ]
        });
    
        var store = Ext.create('Ext.data.TreeStore', {
            model: 'Task',
            proxy: {
                type: 'ajax',
                //the store will get the content from the .json file
                actionMethods : { read : 'GET', create : 'GET' },
                api : { create : 'treegrid.json', read : 'treegrid.json' }
            },
            root : {
            }
        });
    
        var one = new Task({ task : 'foo', duration : 20 });
        var two = new Task({ task : 'foo2', duration : 200 });
        store.getRootNode().appendChild(one)
        store.getRootNode().appendChild(two)
        
        console.log(one.data.parentId, one.data.parentId === null ? 'one.data.parentId === null' : 'one.data.parentId !== null');
        
        store.on('write', function() {
            console.log(store.getById(1) ? 'YUP' : 'CRAP');
            console.log(store.getById(2) ? 'YUP' : 'CRAP');
            console.log(store.getById(1).data.parentId === null ? 'YUP' : 'CRAP');
        });
        store.sync();
    
    });
    Note that parentId is NaN initially after being added to the root node. Shouldn't it be null?

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

      0  

    Default


    Mats, the original bug has been fixed, unit tests are in place, and the code should be in the nightlies.

    If there is another bug showing up even with latest code, you should create a new thread so that a new JIRA ticket can be opened.

  5. #5

Thread Participants: 2

Tags for this Thread