# ID not primary key with not unique values

**URL:** <https://www.ruby-forum.com/t/id-not-primary-key-with-not-unique-values/168853>\
**Category:** Rails\
**Created:** [May 26, 2009, 6:11pm UTC](https://www.ruby-forum.com/t/id-not-primary-key-with-not-unique-values/168853 "2009-05-26T18:11:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@pepe](https://www.ruby-forum.com/u/pepe)\
**Post date:** [May 26, 2009, 6:11pm UTC](https://www.ruby-forum.com/t/id-not-primary-key-with-not-unique-values/168853/1 "2009-05-26T18:11:52Z")

</div>

Sorry for the re-post. Nobody has even answered “no, can’t do”.

I have an ID column in a legacy table of type STRING and could contain  
not unique values. Is there a way of disabling the convention of ID  
being the primary key? How can I assign the values I need to the ID  
column without using SQL, which I already know would work?

ruby: 1.8.6  
rails: 2.3.2  
Database: Oracle 10g

Thanks.

Pepe

---

<div class="post-metadata">

**Author:** ![pepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@pepe](https://www.ruby-forum.com/u/pepe)\
**Post date:** [May 26, 2009, 6:20pm UTC](https://www.ruby-forum.com/t/id-not-primary-key-with-not-unique-values/168853/2 "2009-05-26T18:20:06Z")

</div>

I believe the primary\_key directive will tell AR what field to use as  
the actual PK. Something like:

class MyClass \< AR::Base  
primary\_key :actual\_pk\_field\_name  
end

Hopefully AR would then then ignore the id field.

---

<div class="post-metadata">

**Author:** ![pepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@pepe](https://www.ruby-forum.com/u/pepe)\
**Post date:** [May 26, 2009, 6:21pm UTC](https://www.ruby-forum.com/t/id-not-primary-key-with-not-unique-values/168853/3 "2009-05-26T18:21:17Z")

</div>

On Tue, May 26, 2009 at 6:11 PM, pepe [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Database: Oracle 10g
> 
> Thanks.
> 
> Pepe

Yup, can do 🙂  
See: [ActiveRecord::Base](http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002232)

Technically a primary key is not a primary key if it can contain  
duplicate (not unique) values

Andrew T.  
[http://ramblingsonrails.com](http://ramblingsonrails.com)

[http://MyMvelope.com](http://MyMvelope.com) - The SIMPLE way to manage your savings
