Is it possible to define composite primary key for table using active record? [duplicate]

旧巷老猫 提交于 2019-12-06 20:17:37

问题


I'm using ActiveRecord in a ruby project without rails. I need to define composite primary key for a table.Normally migration creates primary key automatically. Is it possible to define my own composite primary key for a table using active record?


回答1:


There are some gems that give you this ability, such as composite_primary_key.

I don't know if Rails 4 has added support for this, would be very interested to hear if it does.




回答2:


Question has been asked before, checkout: How to set composite key in Rails application

http://compositekeys.rubyforge.org/ might also be useful.



来源:https://stackoverflow.com/questions/17882105/is-it-possible-to-define-composite-primary-key-for-table-using-active-record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!