# Single id column

**URL:** <https://www.ruby-forum.com/t/single-id-column/99398>\
**Category:** Rails\
**Created:** [July 22, 2006, 9:35am UTC](https://www.ruby-forum.com/t/single-id-column/99398 "2006-07-22T09:35:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![frebe73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@frebe73](https://www.ruby-forum.com/u/frebe73)\
**Post date:** [July 22, 2006, 9:35am UTC](https://www.ruby-forum.com/t/single-id-column/99398/1 "2006-07-22T09:35:11Z")

</div>

Is it true that Rails needs a single column to uniquely identify a row  
in table? If yes, doesn’t this limit the database design and disables  
the use of Rails for legacy databases?

/Fredrik

---

<div class="post-metadata">

**Author:** ![frebe73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@frebe73](https://www.ruby-forum.com/u/frebe73)\
**Post date:** [July 22, 2006, 12:41pm UTC](https://www.ruby-forum.com/t/single-id-column/99398/2 "2006-07-22T12:41:24Z")

</div>

“Fredrik B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote  
in message news:removed\_email\_address@domain.invalid…

> Is it true that Rails needs a single column to uniquely identify a row  
> in table? If yes, doesn’t this limit the database design and disables  
> the use of Rails for legacy databases?
> 
> /Fredrik

rails doesn’t currently support composite primary keys. Workarounds have  
been discussed on the list in the past but I don’t have any specific  
posts  
for you. Check the archives

---

<div class="post-metadata">

**Author:** ![frebe73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@frebe73](https://www.ruby-forum.com/u/frebe73)\
**Post date:** [July 23, 2006, 3:55am UTC](https://www.ruby-forum.com/t/single-id-column/99398/3 "2006-07-23T03:55:51Z")

</div>

It is true except for the habm join tables those do not need them  
since they are never instanciated as AR objects.(at least thats what  
my memory is telling me.)

On 7/22/06, Fredrik B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Elliott C.  
removed\_email\_address@domain.invalid  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![frebe73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@frebe73](https://www.ruby-forum.com/u/frebe73)\
**Post date:** [July 23, 2006, 4:09am UTC](https://www.ruby-forum.com/t/single-id-column/99398/4 "2006-07-23T04:09:12Z")

</div>

You can use migrations to add an auto-incrementing id column to your  
existing tables.

```
        - dan

```

–  
Dan K. [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.dankohn.com/](http://www.dankohn.com/)tel:+1-415-233-1000

---

<div class="post-metadata">

**Author:** ![frebe73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@frebe73](https://www.ruby-forum.com/u/frebe73)\
**Post date:** [July 23, 2006, 10:48am UTC](https://www.ruby-forum.com/t/single-id-column/99398/5 "2006-07-23T10:48:21Z")

</div>

> Is it true that Rails needs a single column to uniquely identify a row  
> in table? If yes, doesn’t this limit the database design and disables  
> the use of Rails for legacy databases?

Try [http://compositekeys.rubyforge.org](http://compositekeys.rubyforge.org) - its alpha code, but play with  
it and tell me where the holes are so I can fix them for you.

Cheers  
Nic

---

<div class="post-metadata">

**Author:** ![frebe73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@frebe73](https://www.ruby-forum.com/u/frebe73)\
**Post date:** [July 23, 2006, 5:16am UTC](https://www.ruby-forum.com/t/single-id-column/99398/6 "2006-07-23T05:16:42Z")

</div>

On 7/23/06, Elliott C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It is true except for the habm join tables those do not need them  
> since they are never instanciated as AR objects.(at least thats what  
> my memory is telling me.)

Except that habtm and join tables have been all but outlawed in the RoR  
world.

–
