Results 1 to 3 of 3

Thread: Newbie: 'id' fields in data stores

  1. #1
    Ext JS Premium Member n4hpg's Avatar
    Join Date
    Apr 2010
    Location
    Charlotte, North Carolina, USA
    Posts
    156

    Default Newbie: 'id' fields in data stores

    Having "read the fine manuals" - those from PACKT publishing, this question is regarding what may be contained in the 'id' fields of the data stores. Please forgive me as I'm presently converting from ActiveWidgets...

    All of the example 'id' fields in the data stores are simple integers in the examples such as

    [0,'some data'],
    [1,'more data'],
    [2,'yet more data']

    1. Does ExtJS use these as the controlling index value?
    2. Must it always be an integer?

    The record IDs in my database are string. Some examples would be

    038256
    038256.1
    038256.1.25
    SMNC0.1

    Thus, one would consider an array of:
    ['SMNC0.1','Medicare of North Carolina'],
    ['SKNC0.1','Medicaid of North Carolina'],
    ['SB810.1.5','Blue Cross of North Carolina']

    In a grid control, I would want these record ID fields to be displayed as column data and returned during a click event. If this method is not possible, then I would presume that I should use an index value like the examples and make my record keys a column in the grid thusly:

    [0,'SMNC0.1','Medicare of North Carolina'],
    [1,'SKNC0.1','Medicaid of North Carolina'],
    [2,'SB810.1.5','Blue Cross of North Carolina']

    In this case, the onclick event would need to read from the 2nd column to return the string value as part of the posting back to the server for selection.

    As always, I appreciate the help of those in the support forums who know much more than I do about this!

    Bill

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

    Default

    The ids dont need to be numbers, however it's often the case that it's just an auto-increment number from a database, which is why most of the examples use them. But no, the id isn't used for indexing, just a unique identifier for the record.
    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.

  3. #3

    Default

    Remember, though, that if the record is one that you've created on the client-side and not yet submitted to the host, it will have a "phantom" ID.

    As a general database-design principle, I never use "human" identifiers as "database" primary-keys. An invoice or a part or a widget might have "a number," but that's not the primary-key value that I use ... because: "constants aren't, and variables don't."

    I learned this lesson while re-engineering an application for a health care company that had encoded information into its "provider id's," in what was originally a human-managed system with a much smaller number of providers. Over the years, multiple IDs had been assigned to the same provider, and the same ID had been assigned to multiple providers, and the original database couldn't handle that. Since I knew that the database records would have a long life, I built the system to use an early poor-man's version of what's now known as a UUID-string. The primary key was absolutely random, human-readable but perfectly meaningless. All of the "human" identifiers, ambiguous or not, were first translated to an unambiguous primary-key that was known only to the computer.

    Eventually, of course, they wanted to use those identifiers. Instead, I built the system to automatically coin another string that they could safely use. Thus, the relationship between two disparate systems was "present, but not 'joined at the hip.' " It worked fine.

Posting Permissions

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