habtmテーブルをmigrationで作成
6 月 9th, 2008今更 has_and_belongs_to_many? has_many :through を使おうよ。って声が聞こえてきそうだが、シンプルな用途だと楽なので….
しかし、migrationで作成で作成するのに綺麗な書き方ができていなかったので調べてみた。というメモ書き。
class HogesFugas < ActiveRecord::Migration
def self.up
create_table(:hoges_fugas, :id => false) do |t|
t.column :hoge_id, :integer
t.column :fuga_id, :integer
end
add_index(:hoges_fugas, [:hoge_id, :fuga_id], :unique => true)
end
def self.down
drop_table :hoges_fugas
end
end
キモは create_table の :id => false