59

Is it possible for me to create and use a database table that contains no :id column in ActiveRecord, Ruby on Rails.

I don't merely want to ignore the id column, but I wish it to be absolutely non-existent.

Table Example

:key_column                         :value_column
0cc175b9c0f1b6a831c399e269772661    0cc175b9c0f1b6a831c399e269772661
4a8a08f09d37b73795649038408b5f33    0d61f8370cad1d412f80b84d143e1257
92eb5ffee6ae2fec3ad71c777531578f    9d5ed678fe57bcca610140957afab571

Any more info ( like an :id_column ) would break the whole feature.

How would I implement something like this in rails?

Stefan
  • 9,289
  • 7
  • 38
  • 46
  • 1
    Duplicate: http://stackoverflow.com/questions/825489/rails-activerecord-is-there-a-way-to-perform-operations-on-tables-without-an-id/ – John Topley May 17 '09 at 14:05
  • You should ask those as separate questions. – John Topley May 17 '09 at 14:11
  • removed the second part of the question. asked at [http://stackoverflow.com/questions/874755/ruby-on-rails-activerecord-storing-rows-ordered-and-accessing-with-binary-searc] – Stefan May 17 '09 at 14:41

1 Answers1

135

yup, looks like this:

create_table :my_table, id: false do |t|
  t.string :key_column
  t.string :value_column
end

just make sure to include the

id: false

part.

Michael Brawn
  • 303
  • 2
  • 9
matt
  • 9,113
  • 3
  • 44
  • 46