Results 1 to 10 of 10

Thread: [5.0.1] Model's convert function isn't executed

    You found a bug! We've classified it as EXTJS-15539 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Sencha User
    Join Date
    Sep 2011
    Location
    Taiwan
    Posts
    106

    Default [5.0.1] Model's convert function isn't executed

    Ext version tested:
    Ext 5.0.1


    Browser versions tested against:
    Chrome 38


    Description:
    In my application, the model's id is generated by some of model's fields at front end.
    For example, the file's full path is unique id which is generated by the function:
    Code:
    {
            name: 'path',
            type: 'string',
            convert: function(value, record) {
                return record.get('folder') + '/' + record.get('filename');
     }

    However, if I set the
    idProperty to the generated path, the function convert will be never executed.
    If I remove the idProperty, it just work fine.

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

    Code:
    Ext.define('MyModel', {
        extend: 'Ext.data.Model',
        idProperty: 'path',
        fields: [{
            name: 'folder',
            type: 'string'
        }, {
            name: 'filename',
            type: 'string'
        }, {
            name: 'path',
            type: 'string',
            convert: function(value, record) {
                return record.get('folder') + '/' + record.get('filename');
            }
        }],
        proxy: {
            type: 'memory',
            reader: {
                type: 'array'
            }
        }
    });
    
    
    
    
    var store = Ext.create('Ext.data.Store', {
        model: 'MyModel',
        proxy: {
            type: 'memory',
            reader: {
                type: 'json'
            }
        }
    });
    
    
    var myData = [{
        folder: '/etc',
        filename: 'tt.txt',
        size: 10
    
    
    }];
    
    
    store.loadRawData(myData);
    
    // Should output 'etc/tt.txt'
    console.log(store.getRange()[0].data.path);
    The result that was expected:
    The output in fiddle should be 'etc/tt.txt'.

    The result that occurs instead:
    The output in fiddle is 'MyModel-1'.

  2. #2
    Sencha User
    Join Date
    Sep 2011
    Location
    Taiwan
    Posts
    106

    Default

    Can anyone help me?

  3. #3
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165

    Default

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

  4. #4
    Sencha Premium Member
    Join Date
    Apr 2012
    Posts
    11

    Default

    +1, I haven't been able to find a clean work-around for this. Please fix ASAP.

  5. #5
    Sencha Premium Member
    Join Date
    Apr 2012
    Posts
    11

    Default Source of problem

    In Model.js's constructor we have the following which disregards the fact that our id field has a convert specified and just generates a value for id:

    Code:
    if (!(me.id = id = data[idProperty]) && id !== 0) {
        if (session) {
            identifier = session.getIdentifier(cls);
    id = identifier.generate();
    } else if (modelIdentifier === identifier) {
            id = internalId;
    } else {
            id = identifier.generate();
    }
    
        data[idProperty] = me.id = id;
    me.phantom = true;
    }

  6. #6
    Sencha Premium User
    Join Date
    Sep 2011
    Location
    Tamworth, NSW, Australia
    Posts
    1,307

    Default

    This must still be a problem in 5.1 because my converted fields aren't being processed!

    I thoroughly regret my decision to start using Ext JS 5. It is a complete basket case as far as models are concerned.

  7. #7
    Sencha Premium Member
    Join Date
    May 2013
    Posts
    26

    Default

    Any update on this bug? We are experiencing this very issue.

  8. #8
    Sencha User
    Join Date
    Feb 2009
    Location
    Germany, Nuremberg
    Posts
    39

    Default

    Same thing is in ExtJS 6.0.0. BUT this is a standard behavior for the fields which has a defaultValue (look at the makeInitializeFn function). In case of idProperty field in source code it's hardcoded that defaultValue is null (find out 2 places by link above with this string - idField.defaultValue = null;). So, to make convert function work you need to override Ext.data.Model and comment those two lines of code.

  9. #9

    Default

    Quote Originally Posted by Skay View Post
    Same thing is in ExtJS 6.0.0. BUT this is a standard behavior for the fields which has a defaultValue (look at the makeInitializeFn function). In case of idProperty field in source code it's hardcoded that defaultValue is null (find out 2 places by link above with this string - idField.defaultValue = null. So, to make convert function work you need to override Ext.data.Model and comment those two lines of code.
    I am suffering this bug in ExtJS 6.0.0 too, but I was thinking about overriding Model.makeInitializeFn():3281, where the initialize function is created.
    I guess your workaround maybe will be more suitable. Thanks!

  10. #10
    Sencha Premium Member
    Join Date
    Sep 2011
    Posts
    123

    Default

    It also seems that the convert function is not triggered when loading a record via its load-method.

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
  •