Results 1 to 10 of 10

Thread: Model idProperty

  1. #1
    Ext JS Premium Member
    Join Date
    Sep 2007
    Location
    CT
    Posts
    462
    Vote Rating
    4
      0  

    Default Model idProperty

    Many times tables have natural keys instead of auto generated.

    In these scenarios is it possible to set the Model idProperty to more than one field. If not how do you concatenate two fields in the model and create a composite key???

    or is it better to not specify idProperty and let one be generated?

  2. #2
    Sencha User
    Join Date
    Apr 2011
    Location
    Spain
    Posts
    77
    Vote Rating
    1
      0  

    Default

    I have the same doubt that your. Also how you can change the name of the idProperty??
    Always must be id??or is that because extjs 4.0 still not well developed and soon it will make??

    Please, help...

  3. #3
    Sencha User
    Join Date
    May 2010
    Posts
    12
    Vote Rating
    0
      0  

    Default

    Yes, I have some problem
    in EXT JS 3.x I set IdProperty: 'namefield' and in Update the store (example grid with roweditor) 'namefiled' is use as like as ID... work
    in EXT JS 4.0 I set IdProperty but don't work. If I pass a object with key filed = 'id' work....

  4. #4
    Ext JS Premium Member
    Join Date
    Sep 2007
    Location
    CT
    Posts
    462
    Vote Rating
    4
      1  

    Thumbs up got it.

    In the fields config object of the Model you can create a field say id that uses a convert function to concatenate two fields from the record.

    ex:

    Ext.define("My.Models.ModelA",{extend:"Ext.data.Model",
    fields:[
    {name: 'id', type:'string', convert: function(value,record) {
    return record.get('COLPK1') + record.get('COLPK2')
    }
    },
    {name: 'COLPK1', type:'string'},
    {name: 'COLPK2', type:'string'},
    {name: 'SOMEOTHERCOL', type: string'}
    ],
    idProperty: 'id'
    });

  5. #5
    Sencha User
    Join Date
    Jan 2012
    Location
    New York City
    Posts
    109
    Vote Rating
    2
      0  

    Default

    Doesn't this seem kind of hacky? Shouldnt there be a way of specifying multiple fields as your unique key without having to concatenate things together to create one field?

  6. #6
    Sencha User
    Join Date
    Feb 2009
    Posts
    6
    Vote Rating
    1
      0  

    Default Warning

    Record 0: { COLPK1: 'aa', COLPK2: 'bb' }
    Record 1: { COLPK1: 'a', COLPK2: 'abb' }

    The store will add only one row in this situation because (colpk1[0] + colpk2[0]) == (colpk1[1] + colpk2[1]).

  7. #7
    Sencha Premium Member dawesi's Avatar
    Join Date
    Mar 2007
    Location
    Melbourne, Australia (aka GMT+10)
    Posts
    1,093
    Vote Rating
    56
      0  

    Default

    You could create a custom validator to enforce the composite key.
    Lead Trainer / Sencha Specialist
    Community And Learning Systems

    Lead Architect
    DigitalTickets.net

  8. #8
    Sencha User
    Join Date
    Oct 2007
    Posts
    1
    Vote Rating
    0
      0  

    Default

    You can add a dash in between and make it unique. 'aa-bb' is not the same 'a-abb'

  9. #9
    Sencha User
    Join Date
    Oct 2013
    Posts
    56
    Vote Rating
    3
      0  

    Default

    ValterBorges, thanks, your solution still actual. I'm dealing with an api, which sends me some records with identical 'id' fields, and only such a way I can deal with it.

  10. #10
    Sencha User
    Join Date
    Nov 2015
    Posts
    1
    Vote Rating
    0
      0  

    Default

    great

Similar Threads

  1. Replies: 2
    Last Post: 21 Apr 2011, 2:03 AM
  2. Replies: 6
    Last Post: 19 Apr 2011, 10:28 AM
  3. [API] idProperty not documented in Model
    By mitchellsimoens in forum Sencha Touch 1.x: Bugs
    Replies: 0
    Last Post: 16 Mar 2011, 8:39 AM
  4. [FIXED] Unable to set "idProperty" of Model
    By jeroenvduffelen in forum Sencha Touch 1.x: Bugs
    Replies: 8
    Last Post: 8 Feb 2011, 1:31 PM
  5. JsonStore with idProperty
    By Gunny in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 9 Feb 2010, 1:01 AM

Posting Permissions

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