Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 933
jithendhir92 Avatar asked Jul 26 '13 13:07

jithendhir92


2 Answers

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.

like image 146
Matt Avatar answered Sep 17 '22 17:09

Matt


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

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

like image 25
MatthewFord Avatar answered Sep 18 '22 17:09

MatthewFord