On Aug 18, 6:00 pm, russm <[email protected]> wrote: > On Aug 19, 12:09 am, Jeremy Evans <[email protected]> wrote: > > > You don't need a primary key in the join table, and since you just > > care about the returned primary key, you save the values for the > > inserts into the main model table, and do your own insert into the > > join table. > > while you don't need one, personally I like to use a composite PK for > join tables to protect against inadvertently inserting multiple > identical associations. > > create_table(:authors_books) do > foreign_key :author_id, :authors > foreign_key :book_id, :books > primary_key [:author_id, :book_id] > end > > (and since the join table will probably end up needing to be indexed > anyway, the PK unique index gives you one of those for free)
This is definitely good advice. If you have a primary key in a pure join table, it should be a composite one made up of the two foreign keys. Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
