Just wondering if there’s a way to use migrations to generate join
tables (where the table columns comprise only of foreign keys to other
tables, and where the primary key is all the foreign keys taken
together).
I made the changes manually in MySQL, then did rake db_schema_dump and
it gave something like this:
create_table "apples_oranges", :id => false, :force => true do |t|
t.column "apple_id", :integer, :limit => 10, :null => false
t.column "orange_id", :integer, :limit => 10, :default => 0, :null
=> false
end
The problem is that when you run this code, there’s no primary key
generated on the table. I’ve looked through the source code, and noticed
that the code doesn’t even attempt to create a primary key unless :id =>
true, so I tried:
create_table "apples_oranges", :primary_key => "apple_id,
orange_id", :force => true do |t|
But that didn’t work – it tried to create a column called “apple_id,
orange_id” – not at all what I wanted. I also tried the :primary_key
type for the columns, but that didn’t work, either (not that I expected
it to, since I’m pretty sure that creates autoinc columns).
Looking at the source code some more, I’m pretty sure at this point it
just can’t be done. But I thought I’d ask anyway, hoping to be proved
wrong. So, am I wrong?
Thanks!
Jen