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?
A:
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.
Juha Syrjälä
2009-11-23 18:01:17
A:
Could we see the code you came up with? I ran into this problem as well and would be good to get round the issue!
Colin Asquith
2009-11-30 10:42:31
It is on a branch at github, http://github.com/stimms/SubSonic-3.0 under the compositKeys branch.
stimms
2009-11-30 14:55:13