Scrambling objects ID's for users

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

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs