Rails and “legacy” DB’s
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