• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: exposing the primary key?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: exposing the primary key?


  • Subject: Re: exposing the primary key?
  • From: Musall Maik <email@hidden>
  • Date: Sat, 01 Mar 2014 10:29:06 +0100

Am 28.02.2014 um 22:25 schrieb Theodore Petrosky <email@hidden>:

> I need to create an Entity that will have a user visible id number. I thought I would just use the primaryKey but I recall reading so many times don't use the primaryKey for this.
>
> This is a very simple Entity. It has a description, a Client, and a boolean (isActive). When the user views a list of these Entities, he/she will see:
>
> id number    description     client
>     3456         Blue Dress     Amex
>
> when I insert a new Entity, I only need to supply the description and Client (from a popup). WO will supply the ID number. So why not use the primaryKey here? The user can never edit it. and none of these Entities will ever be deleted.

Here are some more reasons.

Assuming you want the id number to stay constant, you’re giving up any chance of later reorganizing your table structure, which often involves rewriting tables with new primary keys.

And by making the id number separate, you can employ your own schemes on that. You could make it alphanumeric, like „H23M“, which has a far larger value space with fewer digits to remember for people, if they’re supposed to memorize it. (Primary keys could be like that, too, but then you can’t just draw that from a sequence.) You could even decide to change the scheme later on, without assigning new numbers to every old record, just by changing the algorithm that creates those ids.

Nevertheless you should create a unique index on the id number as an additional safety net to get a db exception if your application code fails to ensure uniqueness.

Maik
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Next by Date: Re: Flattened to-one relationship problems
  • Next by thread: Re: Flattened to-one relationship problems
  • Index(es):
    • Date
    • Thread