Page 1 of 2 12 LastLast
Results 1 to 10 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. #1

    Default idProperty set to null falls back to id field

    Setting the idPropert to null in Model falls back to id field where in extjs 4 it was working fine.

  2. #2
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985

    Default

    Thanks for the report. Can you please post a test case which reproduces the issue?
    https://fiddle.sencha.com/#home

  3. #3

    Default

    Test Case

    Ext.define('ComboModel',
    {
    extend: 'Ext.data.Model'
    ,field : ['id' ,'name']
    ,idProperty: null
    });
    var store = Ext.create('Ext.data.Store',
    {
    model : 'ComboModel'
    ,data :
    [
    { name : 'Yes'}
    ,{ name : 'No'}
    ]
    });
    console.log(store.data.items[0].data);

    Result: Object {name: "Yes", id: "ComboModel-1"}
    Expected Result:
    Object {name: "Yes", id: null}

    Here you can see the id is generated where I have configured the idProperty as null.

  4. #4

    Default

    The test case is located at
    https://fiddle.sencha.com/fiddle/fb4

  5. #5
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,250

    Default

    Models must have an idProperty in Ext 5.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  6. #6

    Default

    How can we disable the auto creation of id, since it is required when we need a writable store. The generated id shouldn't be send to the server.

  7. #7
    Sencha User
    Join Date
    Nov 2012
    Posts
    10

    Default

    This change in functionality breaks a lot of EXTJS 4 server implementations and samples, as a lot of the ones I've seen rely on passing an null or 0 id value to force the creation of a new record when the server (ie mysql) is in charge of generating the id numbers using AutoIncrement.

    Some other possible solutions (such as having a different idProperty field from the autoincrement server id) break things like writeAllFields false.

    After some digging in the docs there does seem to be a buried solution, however... adding this:

    PHP Code:
    Ext.define('Myapp.data.identifier.Custom', {
        
    extend'Ext.data.identifier.Generator',
        
    alias'data.identifier.custom',

        
    generate: function () {        return 0;    }
    }); 
    (or alternately return null should work too if that's what your POST processor expects)

    and then the following line into your model definition:

    identifier: 'custom',

    Seems to make everything generally work as it did in EXTJS 4.

    For EXTJS apps that integrate with existing mysql databases that use an autoincrement id field, I don't see any better solution. Having EXTJS stick in some unreleated value ceratinly isn't going to work when the id is server-generated.

  8. #8
    Sencha User
    Join Date
    Nov 2012
    Posts
    10

    Default

    One slight update to this ... returning null actually doesn't work properly (ie doesn't return functionality to the equivalent of EXTJS 4) because the ajax/json writer seems to get upset with a null id ... instead of POSTing the changes with an id value of NULL, it sends a DELETE request with no data. I completely don't understand that action, it doesn't make sense and is likely a bug, but if the server-side PHP looks for zero (instead of null) as the key value then it works ok. Most examples I've seen from others accept both.

  9. #9

    Default

    As you said "Models must have an idProperty in Ext 5". It is ok, but there should be a way to disable the auto-creation of id when a new record is added to the store since this change in functionality breaks a lot of Extjs 4 server implementations since we pass id as null to force the creation of a new record when autoincrement is used to generate the id.

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

    Default

    +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?!

Page 1 of 2 12 LastLast

Posting Permissions

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