Results 1 to 3 of 3

Thread: A model created with a specific id has its id overwritten to a generated id

    Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #1
    Sencha User
    Join Date
    Mar 2012
    Vote Rating

    Default A model created with a specific id has its id overwritten to a generated id

    Version tested:
    • Sencha 2.x
    Browser versions tested against:
    • Chrome 17
    DOCTYPE tested against:
    • <!DOCTYPE html>

    Creating an instance of a simple model and passing in its id field does not stick. The model ends up with a generated id instead of the id passed in.

    Steps to reproduce the problem:
    • Define a model (I'm sticking with the default "id" field -- not using idProperty).
    • Create an instance of that model (passing in an integer for the id).
    • The resulting record created has its "id" field set to a generated value instead of the number I passed in.
    The result that was expected:
    • === 999
    The result that occurs instead:
    • === "ext-record-1"
    Test Case:

            Ext.define('TestModel', {
                extend: '',
                config: {
                    fields: [{
                        name : "id",
                        type : "auto"
                        name : "Name",
                        type : "string"
            var model = Ext.create('TestModel', {
                id : 999,
                Name : "Fred"
            // Creating a simple model should maintain the id
            if ( === 999)
                console.log("Failure. ID was " +;


    Possible fix:

    I was able to correct this by making alterations to the sencha-touch-all-debug.js file. In the constructor definition for (around line 45762) is where my edits come in.

    Line 45762: data = data || convertedData || {};
    Changed to: = data || convertedData || {};
    Reasoning: The original code was updating the local variable 'data' but shortly after the code checks '' for the id and it of course isn't set because '' is an instance variable. I simply made the assignment to the instance variable instead of the local variable.

    Line 45768: data[idProperty] = me.internalId = id;
    Changed to:[idProperty] = me.internalId = id;
    Reasoning: Same reason as before: the original code was updating the local variable instead of the instance variable.

    Line 4596: = me.getIdentifier().generate(me);
    Changed to: me.internalId = = id;
    Reasoning: The if statement before this line checks if the id is set and if not it generates the id. The else statement where this line is was for some reason calling the id generation, too. This shouldn't be because an id was already given that should be used.

    Additional CSS used:
    • N/A
    Operating System:
    • Windows 7

  2. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Gainesville, FL
    Vote Rating


    Thanks for the report.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:

  3. #3
    Sencha User
    Join Date
    Mar 2007
    Haarlem, Netherlands
    Vote Rating


    Hi Colin, is only used internally for the event system. It is not supposed to be accessed directly. In Sencha Touch 2 no properties should EVER be accessed directly. Instead you should be relying on getter and setter functions. In your case you can get the record id by using record.getId(). The id is stored like any other fields inside the data fields of the record. This means if you use the default id field, you can also get the id by using record.get('id') which is exactly what record.getId() does.

    Hope this answers your question.


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