R – ActiveRecord fundamentally incompatible with composite keys

activerecordsubsonic3

I have been attempting to use subsonic for a project on which I'm working. All was going quite well until I encountered a link table with a composite primary key. That is a key made up of the primary keys of the two tables it joins. Subsonic failed to recognize both keys which was problematic. I was going to adjust subsonic to support compound keys but I stopped and though "Maybe there is a reason for this". Normally active record relies on a single primary key field for every record, even in link tables. But is this necessary? Should I just give up on active record for this project or continue with my modifications?

Best Answer

Ruby on Rails does not support composite primary keys in model object out of the box. However, there are plugins that accomplish that, for example this.

You can have composite primary key on a join table, but Rails will not create that primary key, you have to create it manually. See this guide.