Define a unique primary key based on 2 columns

后端 未结 7 582
长情又很酷
长情又很酷 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:38

    Depending on your use case you might want to try out composite key gem which allows you to define composite primary keys and also ehances ActiveRecord to deal with this kind of model (helps a lot for associations to this model or for url_for helpers etc.).

    So if you plan in using this model as any other rails model the gem will help a lot.

提交回复
热议问题