Results 1 to 5 of 5

Thread: store creates duplicate data in case of mapping

  1. #1
    Sencha User
    Join Date
    Nov 2009
    Location
    Switzerland
    Posts
    4

    Default Answered: store creates duplicate data in case of mapping

    If data supplied is mapped then store creates duplicate data (Ext v 5.1.0)


    I use a store that loads a dummy json, but the records are duplicated, containing both mapped and field names.


    Basically I have an application in ExtJs 4, where it is working properly and after migration to v5.1.0 I encountered this issue.
    Someone has any hints?

    https://fiddle.sencha.com/#fiddle/j71


    Thank you

    Attachment 51894

    Code:
    Ext.define('My.Model', {
        extend: 'Ext.data.Model',
        idProperty: 'EventId',
        fields: [
            {
                mapping: 'id',
                name: 'EventId',
                type: 'int'
            },{
                mapping: 'title',
                name: 'Title',
                type: 'string'
            }
        ],
        proxy: {
            type: 'ajax',
            reader: {
                type: 'json',
                rootProperty: 'events',
                totalProperty: 'count'
            },
            writer: {
                type: 'json',
                rootProperty: 'events',
                writeAllFields: true,
                encode: true,
                nameProperty: 'name'
            }
        }
    });    
    
    
    Ext.define('Dummy.Store', {
        extend: 'Ext.data.Store',
        model: 'My.Model',
        autoLoad: true,
         proxy: {
            api: {
                read: 'http://localhost/dummy/data/json.php'
            },
            type: 'ajax',
            enablePaging: true,
            reader: {
                type: 'json',
                rootProperty: 'events',
                totalProperty: 'count'
            },
            writer: {
                type: 'json',
                allowSingle: false,
                writeAllFields: true,
                nameProperty: 'name'
            }
        }
        listeners: {
            load: function(store, records, successful){
                Ext.each(records, function(rec){
                    console.log(rec.data);
                });
            }
        }
    });

  2. hmmm, yes, bug.
    I have never used mapping to transform the data from server, that is why never met this terrible bug. Aber es ist logisch, as soon as you are putting one more token in the mechanism, the probability of crash increasing.
    I think you must move or recreat this issue in bugs section.
    Jedenfalls thank you, I will use this case as stand alone chapter in my book.

  3. #2
    Sencha User yeghikyan's Avatar
    Join Date
    Mar 2009
    Location
    München
    Posts
    574
    Answers
    99

    Default

    Code:
    {      mapping: 'id',
          name: 'EventId',
          type: 'int'
    }
    I am not sure, but may you try rename the 'id' to something like 'theId', maybe it will help you. Or just reproduce the bug in the fiddle?
    "The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague." – Edsger W. Dijkstra

  4. #3
    Sencha User
    Join Date
    Nov 2009
    Location
    Switzerland
    Posts
    4

    Default

    @yeghikyan here is the fiddle url: https://fiddle.sencha.com/#fiddle/j71

  5. #4
    Sencha User yeghikyan's Avatar
    Join Date
    Mar 2009
    Location
    München
    Posts
    574
    Answers
    99

    Default

    So as I can see duplicated only 'id' property of record. Actually it is not duplicated, 'id' property is used by record for identification, if it is not sended by server, it will be autogenerated.
    "The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague." – Edsger W. Dijkstra

  6. #5
    Sencha User
    Join Date
    Nov 2009
    Location
    Switzerland
    Posts
    4

    Default

    All the fields are "duplicated", not only the id:

    {"id":1001,"title":"Vacation","notes":"Have fun","EventId":1001,"Title":"Vacation","Notes":"Have fun","RRule":null}

    If I want to change the title for example, what field should I update: "title" or "Title"?

    This is a normal behaviour in v.5.1.0?

    In v.4.2 I my record looked like: {"EventId":1001,"Title":"Vacation","Notes":"Have fun","RRule":null} and now the update/create/move functions are not working anymore because they were changing only the value of mapped field, the output being mixed( old values stored in name of the field, new ones stored in mapped fields ), like:

    {"id":1001,"title":"Vacation","notes":"Have fun","EventId":1001,"Title":"Updated vacation","Notes":"Updated have fun","RRule":null}


    Quote Originally Posted by yeghikyan View Post
    So as I can see duplicated only 'id' property of record. Actually it is not duplicated, 'id' property is used by record for identification, if it is not sended by server, it will be autogenerated.

  7. #6
    Sencha User yeghikyan's Avatar
    Join Date
    Mar 2009
    Location
    München
    Posts
    574
    Answers
    99

    Default

    hmmm, yes, bug.
    I have never used mapping to transform the data from server, that is why never met this terrible bug. Aber es ist logisch, as soon as you are putting one more token in the mechanism, the probability of crash increasing.
    I think you must move or recreat this issue in bugs section.
    Jedenfalls thank you, I will use this case as stand alone chapter in my book.
    "The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague." – Edsger W. Dijkstra

Tags for this Thread

Posting Permissions

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