Active Record and non-numeric, natural primary keys?

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
(Intelligent Versus Surrogate Keys), 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,

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 L. 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
(Intelligent Versus Surrogate Keys), 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,