Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: idProperty set to null falls back to id field

    Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #11
    Sencha User
    Join Date
    Feb 2012
    Posts
    13

    Default

    Use this as a fiddle to see differences in the output between Ext 4 and Ext 5. This can make HUGE differences! And worst of all, it seems like there is no way of getting back the old behaviour. So even server code has to change because Ext can not send null for ids anymore. I mean seriously...

    Code:
    //Ext.define('NullIdGenerator', {
    //    extend: 'Ext.data.identifier.Generator',
    //    alias: 'data.identifier.null',
    //
    //    generate: function () {        return;    }
    //});
    
    
    Ext.define('User',
               {
                   extend: 'Ext.data.Model',
                   idProperty:'id',
                   //identifier: 'null',
                   fields: [{
                       name: 'id'
                   },{
                       name:'name'
                   }]
               })
    
    
    
    
    Ext.application({
        name : 'Fiddle',
    
    
        launch : function() {
            var user = Ext.create('User', {name: 'A user'});
            var user2 = Ext.create('User',{name: 'A second user'});
            var store = Ext.create('Ext.data.Store', {model: 'User'});
            store.add([user, user2]);
            
            Ext.widget('component', {
                html: user.get('id') + '</br>' + user2.get('id') + '</br></br>',
                renderTo:Ext.getBody()
            });
            
            Ext.widget('dataview',{
                store: store,
                tpl: '<tpl for="."><div>{name}</div></tpl>',
                renderTo:Ext.getBody(),
                itemSelector: 'div'
            });
        }
    });

  2. #12
    Ext GWT Premium Member
    Join Date
    Oct 2009
    Location
    Geelong, Australia
    Posts
    12

    Default

    Completely agree - why is this bug closed? Upgrading from Ext JS 4 to 5 should not break existing logic the way that this change does.Creating a new Model can create an id with unique string value (as is the case in Ext JS 5) BUT the logic behind the process SHOULD NOT automatically set the designated idProperty field (which is equivalent to the primary key of the database in most situations) to the same value.The change in behaviour from Ext JS 4 to 5 means there is now NO WAY we can send a null value for the idProperty field to the backend. In Ext JS 4 this represented "inserting a new record". We now have some bizarre string sent for a field defined as an 'int' (e.g. 'NAMESPACE.model.ModelClass-3'). There has to be an easy way to leave the idProperty field alone and STILL have an internal id field to represent uniqueness within the JS... any ideas???

  3. #13
    Sencha User
    Join Date
    Feb 2012
    Posts
    13

    Default

    Quote Originally Posted by ggierer View Post
    Completely agree - why is this bug closed? Upgrading from Ext JS 4 to 5 should not break existing logic the way that this change does.Creating a new Model can create an id with unique string value (as is the case in Ext JS 5) BUT the logic behind the process SHOULD NOT automatically set the designated idProperty field (which is equivalent to the primary key of the database in most situations) to the same value.The change in behaviour from Ext JS 4 to 5 means there is now NO WAY we can send a null value for the idProperty field to the backend. In Ext JS 4 this represented "inserting a new record". We now have some bizarre string sent for a field defined as an 'int' (e.g. 'NAMESPACE.model.ModelClass-3'). There has to be an easy way to leave the idProperty field alone and STILL have an internal id field to represent uniqueness within the JS... any ideas???
    What I did and it worked for our Use-Case was, i introduce a new field (e.g. 'clientId') and set the idProperty to 'clientId'. So this new field would get the new autogenerated id where the other id can then be null and also be sent null to the server.

    But in general i totally agree with you.
    We're doing this upgrade from Ext 4 to 5 and it's gonna be the last ExtJs Update that we're gonna do to this product. It's just too time consuming and dangerous in some cases.

    Because of some of these changes we're experiencing silent changes in business logic (for example vastly different behaviour of convert method on models) which seems fine at first and you only can get lucky to see the difference.

  4. #14
    Ext GWT Premium Member
    Join Date
    Oct 2009
    Location
    Geelong, Australia
    Posts
    12

    Default

    This is a good idea for adding new records but unfortunately won't work for models when using find/erase actions which require the "real" pk field. We need the correct idProperty:PK field mapping defined in the model.

    I am now looking at adding the appropriate logic in the backend to handle the auto-generated values - thankfully the default generated "strings" cannot be parsed into our required "int" PKs so it should be easy to replace the strings with "null" values.

    The biggest gripe remains: how can such a fundamental change be made to one of the core workflows in the data package? And there appears to be no workaround...

  5. #15
    Sencha User
    Join Date
    Feb 2012
    Posts
    13

    Default

    Quote Originally Posted by ggierer View Post
    This is a good idea for adding new records but unfortunately won't work for models when using find/erase actions which require the "real" pk field. We need the correct idProperty:PK field mapping defined in the model.
    True, then this won't work for you i guess.

    And as for the rest, i don't know why.
    I don't understand a lot of these breaking changes. The change in the behavior of the convert method on the model being on of the weirdest cases for me.

    These things are definitely a showstopper for using extjs. In our company we're stuck with the decision, for now at least. We wouldn't use it a second time though.

  6. #16
    Ext GWT Premium Member
    Join Date
    Oct 2009
    Location
    Geelong, Australia
    Posts
    12

    Default

    I have put in a change request for an additional Ext.data.field.Field property:


    useNullOnCreate:true


    If true, the proxy api "create" function would submit "null" for the field. Internally you can still have auto-generated id's but the create action would submit "null" if configured this way.

    I have temporarily resolved our issue in the backend but the above change would be a better long term solution.

  7. #17
    Ext JS Premium Member
    Join Date
    May 2008
    Location
    Austria, Vienna
    Posts
    264

    Default

    My ExtJS 3 to 6 conversion also has this problem, is there a fix already?
    Having autogenerated IDs for ExtJS to work internally with is ok as long as those dont' get sent to the backend on sync.

    Edit: I just found a solution that work so far: define the id column as
    Code:
    persist: false
    .
    https://www.sencha.com/forum/showthr...=1#post1112187

  8. #18

    Default Workaround

    Quote Originally Posted by cma_upper View Post
    +1 for "there should be a way to disable the auto-creation of id when a new record is added to the store"!(+1000 if i could)Breaks a lot of our functionality in the company. We're upgrading from Ext 4 to Ext 5 now for weeks because of these sort of things and our mood regarding extjs is.. well, let's just say terrible..

    And why the hell is this closed?!

    After creation of model instance, set the id property to null.

    Code:
    var modelInstance = Ext.create('MyModel');
    modelInstance.set('idProperty', null);

  9. #19
    Sencha Premium Member
    Join Date
    Feb 2016
    Posts
    12

    Default Multiple Id property

    I am facing similar issue with Ext 6.5.1

    I have 10 fields in my model out of which 3 fields makeup a composite primary key. This is GET only, NO updates are going to be performed.

    My rest calls are appended with id=Example.model.ModelA-1

    Some of the methods i tried:

    Method 1: Returns: localhost:9090/example/rest/test?_dc=1502480515851&id=Example.model.ModelA-1
    Code:
    
    var modelInstance = Ext.create('Example.model.ModelA');
    modelInstance.set('idProperty', null);
    
    modelInstance.load(null, {
        params: {
            aParam: 'A',
            bParam: 'B',
            cParam: 'D'
    },
    Method 2: Returns: localhost:9090/example/rest/test?_dc=1502480750662&aParam=A&bParam=B&cParam=C&id=Example.model.ModelA-1

    Code:
    Ext.define('Example.model.ModelA', {
        extend: 'Ext.data.Model',
    
        requires: [
            'Ext.data.proxy.Ajax'
    ],
        idProperty: null,
        fields: [
            {name: 'aParam', type: 'auto'},
            {name: 'bParam', type: 'auto'},
            {name: 'cParam', type: 'auto'},
           {...other fields...}
    }
    Any thoughts ?

  10. #20

    Default

    Ext.define('Example.model.ModelA', {
    extend: 'Ext.data.Model',

    requires: [
    'Ext.data.proxy.Ajax'
    ],
    idProperty: 'idField',
    fields: [
    {name: 'idField', type: 'auto'},
    {name: 'aParam', type: 'auto'},
    {name: 'bParam', type: 'auto'},
    {name: 'cParam', type: 'auto'},
    {...other fields...}
    }

Page 2 of 2 FirstFirst 12

Posting Permissions

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