Hi, Are we supposed to use numeric, auto-incremented surrogate keys with Active Record, or are natural (intelligent), non-numeric primary keys perfectly acceptable (advised)? There is an eternal debate on this subject (http://www.bcarter.com/intsurr1.htm), but I was wondering if Active Record was designed with the idea of "surrogate keys" in every table. That''s what we see mostly in every AR tutorial... Thanks, --------------- Philippe Lang Attik System
Cayce Balara
2006-Oct-25 13:34 UTC
Re: Active Record and non-numeric, natural primary keys?
The Rails convention is to use an auto-incrementing primary key named id on your tables. Rake migrations will create this field automatically. You can by all means instruct AR to use your key field instead of the id field, but then you are doing extra work. Your linked article discusses the topic quite well and hits all the salient points. If you accept that both methods have pluses and minuses of their own accord and are generally no more or less ''better'' overall than each other, then the determining factor in a RoR environment is the additional ease of coding and productivity gains to be had by following the convention (which in this case is based on a surrogate keys framework). The beauty of Rails ... well, one of the beauties of Rails ... is that you can let Rails handle the mundane grunt-work and you can concentrate on design and features. Why be bothered with that stuff? c. Philippe Lang wrote:> Hi, > > Are we supposed to use numeric, auto-incremented surrogate keys with > Active Record, or are natural (intelligent), non-numeric primary keys > perfectly acceptable (advised)? > > There is an eternal debate on this subject > (http://www.bcarter.com/intsurr1.htm), but I was wondering if Active > Record was designed with the idea of "surrogate keys" in every table. > That''s what we see mostly in every AR tutorial... > > Thanks,-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---