Specify custom primary key in migration

后端 未结 2 899
余生分开走
余生分开走 2020-12-05 16:46

I have a data structure:

  t.integer :userID
  t.string :apikey
  t.integer :characterID

The userID should be the primary key (name is not

2条回答
  •  盖世英雄少女心
    2020-12-05 17:05

    Instead of circumventing the ActiveRecord model, I made userID a normal column and used

    validates_uniqueness_of :userID, :message => "userID needs to be unique"
    

    on the model to validate it.

提交回复
热议问题