Using multiple columns as primary key


#1

Hi!

I’m trying to use a primary key made up of two columns in my model’s
table.
But looking at the docs, it looks like ActiveRecord only supports using
one field as primary key.

Can anyone point me in a direction of this or verify that it’s not
supported?

Greetings,
Gitte W.


#2

Composite primary keys are not supported… yet. But keep an eye on
Edge Rails.

Gitte W. wrote:

Hi!

I’m trying to use a primary key made up of two columns in my model’s
table.
But looking at the docs, it looks like ActiveRecord only supports using
one field as primary key.

Can anyone point me in a direction of this or verify that it’s not
supported?

Greetings,
Gitte W.


#3

Hi I’m a total beginner with either Ruby or Rails.

I am having the same issue and was also looking for a confirmation on
this matter. Since multi-column primary keys are not currrently
supported, and the legacy table I have uses four varchar columns as the
primary key. As a work-around during prototyping, I created a view that
does the following:

CREATE VIEW WorkAround
AS
SELECT f1 + ‘-’ + f2 + ‘-’ + f3 + ‘-’ + f4
AS id
FROM LegacyTable

It’s not perfect but it suffcies for my purposes.

By the way, can anybody tell me what happened to http://
manuals.rubyonrails.com?