Migration example for a join table

Posted by Jeff Kupperman Fri, 28 Sep 2007 15:15:24 GMT

... because I will forget again:

class GamesUsers < ActiveRecord::Migration

	def self.up		
		create_table :games_users, :id => false do |t|
			t.column :user_id, :integer
			t.column :game_id, :integer
		end
		add_index :games_users, [:user_id]
		add_index :games_users, [:game_id]
	end
	
	def self.down	
		drop_table :games_users
	end
	
end

Leave a comment, View comments, View trackbacks

Your Comments.

Leave your own response

Spread the word.

Jeff Kupperman supports RSS (Real Simple Syndication), and Trackbacks from other blogs.

RSS feed for this post Trackback URI

Your Reply

Comment Form.

Fields denoted with a "*" are required.

You may also like to leave your email or website.