# Scrambling objects ID's for users

**URL:** <https://www.ruby-forum.com/t/scrambling-objects-ids-for-users/133986>\
**Category:** Rails\
**Created:** [April 6, 2008, 4:28am UTC](https://www.ruby-forum.com/t/scrambling-objects-ids-for-users/133986 "2008-04-06T04:28:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![halfbyte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7ab992/32.png) [@halfbyte](https://www.ruby-forum.com/u/halfbyte)\
**Post date:** [April 6, 2008, 4:28am UTC](https://www.ruby-forum.com/t/scrambling-objects-ids-for-users/133986/1 "2008-04-06T04:28:05Z")

</div>

Hello. I would to replace a standard records idenfiers -  
1,2,3,50043,43242 etc by a something like guid. I would like to use it  
everywhere - in assocations, etc, because i don’t wont to user estimate  
my database size by simple reading ids. Whats the solution? Is somewhere  
a rails plugin (i use rails 2.0.2)? I have problem with standard  
approach - by simple replacing id column by string and generate guid in  
callbacks - i use a postgresql database and my rails app raises some  
error with currval. Any solution? thanks

---

<div class="post-metadata">

**Author:** ![halfbyte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7ab992/32.png) [@halfbyte](https://www.ruby-forum.com/u/halfbyte)\
**Post date:** [April 6, 2008, 4:45am UTC](https://www.ruby-forum.com/t/scrambling-objects-ids-for-users/133986/2 "2008-04-06T04:45:02Z")

</div>

Jan Kowalski wrote:

> Hello. I would to replace a standard records idenfiers -  
> 1,2,3,50043,43242 etc by a something like guid. I would like to use it  
> everywhere - in assocations, etc, because i don’t wont to user estimate  
> my database size by simple reading ids. Whats the solution? Is somewhere  
> a rails plugin (i use rails 2.0.2)? I have problem with standard  
> approach - by simple replacing id column by string and generate guid in  
> callbacks - i use a postgresql database and my rails app raises some  
> error with currval. Any solution? thanks

This is not really a Rails issue. A surrogate primary key can be any  
data type and value so long as it is called id (or whatever key name  
format you have selected in your environment.rb) and the key values are  
unique and auto-generated by the DBMS. You will have to override the  
Rails postgresql adaptor defaults used for migrations of course.

PostgreSQl 8.3 has a UUID data type and there are Postgres contributed  
libraries and modules for rolling your own uuid generators so I would  
recommend you start by reading the 8.3 docs on this data type. The  
posgres mailing list is a good source of support as well.
