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
    Posts
    1
    Vote Rating
    0
    colinmathews is on a distinguished road

      0  

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

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


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

    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:
    • model.id === 999
    The result that occurs instead:
    • model.id === "ext-record-1"
    Test Case:

    Code:
            Ext.define('TestModel', {
                extend: 'Ext.data.Model',
                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 (model.id === 999)
                console.log("Success!");
            else
                console.log("Failure. ID was " + model.id);

    HELPFUL INFORMATION

    Possible fix:

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

    Line 45762: data = data || convertedData || {};
    Changed to: me.data = data || convertedData || {};
    Reasoning: The original code was updating the local variable 'data' but shortly after the code checks 'me.data' for the id and it of course isn't set because 'me.data' 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: me.data[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.id = me.getIdentifier().generate(me);
    Changed to: me.internalId = me.id = 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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,756
    Vote Rating
    828
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Thanks for the report.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    10
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    Hi Colin,

    model.id 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.

    Best,
    Tommy

Thread Participants: 2

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi