# Using multiple columns as primary key

**URL:** <https://www.ruby-forum.com/t/using-multiple-columns-as-primary-key/51595>\
**Category:** Rails\
**Created:** [January 4, 2006, 12:45am UTC](https://www.ruby-forum.com/t/using-multiple-columns-as-primary-key/51595 "2006-01-04T00:45:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mamatux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mamatux](https://www.ruby-forum.com/u/mamatux)\
**Post date:** [January 4, 2006, 12:45am UTC](https://www.ruby-forum.com/t/using-multiple-columns-as-primary-key/51595/1 "2006-01-04T00:45:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mamatux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mamatux](https://www.ruby-forum.com/u/mamatux)\
**Post date:** [January 4, 2006, 2:03am UTC](https://www.ruby-forum.com/t/using-multiple-columns-as-primary-key/51595/2 "2006-01-04T02:03:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mamatux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mamatux](https://www.ruby-forum.com/u/mamatux)\
**Post date:** [February 8, 2006, 10:49pm UTC](https://www.ruby-forum.com/t/using-multiple-columns-as-primary-key/51595/3 "2006-02-08T22:49:27Z")

</div>

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](http://manuals.rubyonrails.com)?
