# Without the magical id column in table

**URL:** <https://www.ruby-forum.com/t/without-the-magical-id-column-in-table/160519>\
**Category:** Rails\
**Created:** [February 17, 2009, 11:10am UTC](https://www.ruby-forum.com/t/without-the-magical-id-column-in-table/160519 "2009-02-17T11:10:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![on9west](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/6f9a4e/32.png) [@on9west](https://www.ruby-forum.com/u/on9west)\
**Post date:** [February 17, 2009, 11:10am UTC](https://www.ruby-forum.com/t/without-the-magical-id-column-in-table/160519/1 "2009-02-17T11:10:47Z")

</div>

Dear all

In rails, the are some magical column such as id, created\_at, updated\_at  
can make things easier.

However, within my organization, due to whatever reason, the data type  
identity is not allowed to use. So, the magical id column cannot be used  
in my rails project. I know that there is some actions rely on the like  
[http://localhost:3000/controller/action/123](http://localhost:3000/controller/action/123), where 123 is the :id…and  
in edit\_path(:id), It seems that without the id column I cannot perform  
these actions… Am I right?

Should I change other web framework in my project (but I love rails  
^\_^)? Or any workaround available in rails if my table without the id  
column? Is it really a matter for the CRUD action without id column?

Please give me some advices.

Thank you.

Valentino

---

<div class="post-metadata">

**Author:** ![on9west](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/6f9a4e/32.png) [@on9west](https://www.ruby-forum.com/u/on9west)\
**Post date:** [February 17, 2009, 11:48am UTC](https://www.ruby-forum.com/t/without-the-magical-id-column-in-table/160519/2 "2009-02-17T11:48:11Z")

</div>

On 17 Feb 2009, at 10:10, Valentino L. wrote:

> in my rails project. I know that there is some actions rely on the  
> like  
> [http://localhost:3000/controller/action/123](http://localhost:3000/controller/action/123), where 123 is  
> the :id…and  
> in edit\_path(:id), It seems that without the id column I cannot  
> perform  
> these actions… Am I right?

Rails assumes very much that there is a primary key (as in a single  
column that uniquely identifies rows i don’t think it actually cares  
whether it is labelled a primary key in the database), you don’t have  
to call it id though (see set\_primary\_key). I’m not sure what would  
happen if the primary wasn’t auto increment (or associated with a  
sequence etc.) but you could give it a go.

Fred

---

<div class="post-metadata">

**Author:** ![on9west](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/6f9a4e/32.png) [@on9west](https://www.ruby-forum.com/u/on9west)\
**Post date:** [February 17, 2009, 4:51pm UTC](https://www.ruby-forum.com/t/without-the-magical-id-column-in-table/160519/3 "2009-02-17T16:51:00Z")

</div>

You can use a UUID instead… never used it myself though.

google “rails uuid”

On Feb 17, 5:10 am, Valentino L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![on9west](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/6f9a4e/32.png) [@on9west](https://www.ruby-forum.com/u/on9west)\
**Post date:** [February 19, 2009, 5:22am UTC](https://www.ruby-forum.com/t/without-the-magical-id-column-in-table/160519/4 "2009-02-19T05:22:47Z")

</div>

Hi there,

I have worked with legacy databases that had no ‘id’ column but had a  
different column as primary key. You only need to add the following  
code to your models:

self.primary\_key = ‘your\_primary\_key\_column\_here’

I hope this helps.

Pepe

On Feb 17, 5:10 am, Valentino L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
