Archive for the 'web' Category

Rails and “legacy” DB’s

Sunday, June 17th, 2007

I’m importing a (so-called) “legacy” db, and was having some issues with creating associations because the primary key wasn’t named id. To fix this, simply use set_primary_key on the class, and then use foreign_key to create associations between classes as usual.

class LegacyDatabaseTable < ActiveRecord::Base

  set_primary_key :this_is_not_named_id

  # …

end

notes about computers and lifestyle