> This is a long standing bug in Rails that I don't think they plan on
> fixing. See http://dev.rubyonrails.org/ticket/1031. The suggested
> workaround if you want to use a primary key in a join table is to
> change to has_many :through. There is a plugin for Rails 1.1 that
> works around the bug:
It's not a bug, habtm join tables are working as intended. If a join
model is what you want, use has_many :through.
This is a bug. Features can be turned off.
Regardless, this 'feature' has surprised, confused, and flustered many
a developer. In this regard it minimally violates the spirit of the
framework. Saying "it's supposed to work that way" misses the point.
The goal is to take the pain out of web development and this is
Adding a surrogate key to a pure join table _certainly_ isn't good db
design. You'll probably want a composite primary key from the two
columns to avoid duplicates.
I beg to differ. I (and many others) would argue tables should always
have a primary key that has no other use (i.e. don't use composite
keys or keys like SSNs which you *think* won't change but sometimes
do, are harder to index, etc). If you don't you will almost certainly
have messy data problems later.