Multi-column primary key in joining tables


What is the convention for primary key fields in joining tables in RoR?

I have a model representing a joining table, and I can’t seem to
prevent ActiveRecord’s find method from looking for an id column. I
don’t have an auto-incremented field in my table (happy to add one if
that is the convention), and therefore my primary key is the
combination of the 2 foreign keys.


Short answer: You can’t have multi-column prikeys.

Rails assumes single column primary keys. By having a multi-column
prikey, you’re breaking that basic assumption, and you’ll have to do
all sorts of non-standard magic in order to get it to work. Sorta like
multi-databases (although much worse).

From DHH himself:

eden li wrote:

Short answer: You can’t have multi-column prikeys.

If it’s good enough for DHH, it’s good enough for me. :slight_smile: