1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    26
    Vote Rating
    0
    redmagic is on a distinguished road

      0  

    Default Answered: Store.add, store.sync, how do I update my record id?

    Answered: Store.add, store.sync, how do I update my record id?


    Hi,

    I've got a store with a rest proxy to communicate with the server.

    My question is how do I update a added record with the id given to it by the server?

    First, the record is added:
    Code:
            var newClass = Ext.create('SM.model.SchoolClass', {
                name: name,
                students: []
            }); //Added without id
    
    
            this.store.add(newClass);
    
    
            this.store.sync();
    The json going back and forth is as follows:

    POST
    Code:
    {"id":null,"name":"testmij","students":[]}
    Response
    Code:
    {"id":"b7ry8ina4ckr4k44x0ad5tpi6","name":"testmij","students":[]}
    Then I handle the response on the stores write event:
    Code:
            this.store.on({
                write: function (store, operation, options) {
                    this.handleResponse(operation);
                },
                scope:this
            });
    ...
    ...
        handleResponse: function (operation) {
    
    
            if (operation.wasSuccessful()) {
    
    
                switch (operation.action) {
                    case 'create':
                        var response = Ext.decode(operation.response.responseText);
                        this.addLocalClass(response.id, response.name, true);
                        this.getClassTabs().setActiveTab(response.id);
                        this.store.each(function(record) {
                            console.log(record.data.id,record.data.name)// This shows the added record, but without id
                        });
                        break;
                    case 'read':
                    break;
                    case 'update':
                    break;
                    case 'destroy':
                        this.removeLocalClass(operation.records[0].data.id);
                    break;
                }
    
    
            }
        },
    I would like to know what the proper way is to update the record with the id from the server.

    Kind regards,

    Arjen

  2. For one thing, you are not sending { success: true, data:[ .. ] }

    Scott.

  3. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,918
    Answers
    655
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    When you insert the record, it adds it to the store, the response then updates the record with id
    When updating, the id determines the record that is updated.

    This is handled for you as long as your response is correctly formatted.

    Scott.

  4. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    26
    Vote Rating
    0
    redmagic is on a distinguished road

      0  

    Default


    Hi,

    Thanks for your reply.

    I still have the problem that my local record is not automatically updated with the server response values.

    A workaround I use now is to do it manually:
    Code:
    operation.getRecords()[0].data.id = response.id;
    This does not feels very robust, and for batch operations it would require more workaround code.

    Is there something wrong with the server response format? Or should I define the proxy on the model instead of the store?

    Am a bit stuck here, help is very welcome.

    Kind regards,

    Arjen

  5. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,918
    Answers
    655
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    For one thing, you are not sending { success: true, data:[ .. ] }

    Scott.

  6. #5
    Sencha User
    Join Date
    Dec 2011
    Posts
    26
    Vote Rating
    0
    redmagic is on a distinguished road

      0  

    Default


    Thanks Scott,

    I'll give it a try.

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi