On Dec 21, 4:25 pm, "Maurício Linhares" <[email protected]>
wrote:
[...]
> > 3 - Perhaps create a specific identify/key as a new column that you use, but
> > is not the database Rails ID?  How's this sound?
>
> I think this is a way to complex way to solve a simple problem :)

I totally disagree.  I think this is probably the best way to do it in
certain cases -- namely, when you *know* that the key is not going to
change.  And then you might as well use that key as the primary key,
instead of an autogenerated key.

A good example of this might be a table of countries.  If the data is
like this:

countries:
  -
    code: US
    name: United States
  -
    code: CA
    name: Canada
  -
    code: MX
    name: Mexico

...then it is perfectly reasonable, in order to avoid the
unpredictability of an autogenerated primary key, to find countries by
code (method 3), and it will work far more reliably than method 2 and
more readably than method 1.  It's not overcomplicated at all.  It may
even be worthwhile to use code as the primary key column, forgoing an
autogenerated key.  (In this case, I think I'd still use the
autogenerated key -- country abbreviations *can* change -- but you
need to look at your data and decide what suits it best.)

>
> -
> Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) 
> |http://blog.codevader.com/(en)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to