Rails migration: t.references with alternative name?

前端 未结 5 1091
情歌与酒
情歌与酒 2021-01-30 05:48

So I have a create_table like this for Courses at a School:

create_table :courses do |t|
  t.string :name
  t.references :course
  t.timestamps
end
5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-30 06:48

    You can do this all in the initial migration/column definition (at least currently in Rails 5):

    t.references :transferable_as, index: true, foreign_key: {to_table: :courses}
    t.references :same_as, index: true, foreign_key: {to_table: :courses}
    

提交回复
热议问题