Search code examples
ruby-on-railsactiverecordprimary-keylegacy-database

Active Record legacy table with no primary key


I'm connecting my Rails application with a legacy database. Some of this tables don't have a primary key and I have no way to add one.

Is there any way to to configure an Active Model not to have a primary key?

Thanks!


Solution

  • You can define primary key by using self.primary_key = <pk_field> like so:

    class User < ActiveRecord::Base
        self.table_name = "user"
        self.primary_key = "id"
    end