Define a unique primary key based on 2 columns

后端 未结 7 601
长情又很酷
长情又很酷 2021-01-31 02:52

I would like to define a unique key for records based on 2 columns : \'id\' and \'language\'

to let the user submits the following strings : id=1 language=en value=bl

7条回答
  •  太阳男子
    2021-01-31 03:30

    As I said in my comments you will be fighting rails if you try this, and it isn't really supported out of the box. you can look at http://compositekeys.rubyforge.org which offers a way to do composite primary keys in rails. I haven't used it, as I haven't had a need yet (normally when I have something that is composite key like it is just a join table with no primary key and a unique index on the joined pair (HABTM).

提交回复
热议问题