# This migration file creates the many-to-many relationship between # actors and movies. In particular, it creates the join table named # actors_movies # # IMPORTANT: Rails expects that the join table has the model names presented # in alphabetical order (e.g. actors come before movies) # # The skeleton of this migration file was created with this command # ruby script/generate migration CreateActorsMovies # # The options for this connecting table indicate that "id" will not be # present and that actor_id and movie_id cannot have null values. # # This migration file also sets up an index for efficient look-up. # # To complete the relationship for the models, the following need to be added: # To app/models/actor.rb # has_and_belongs_to_many :movies # To app/models/movie.rb # has_and_belongs_to_many :actors # # A similar example is covered in Learning Rails, pp. 162 - 165 class CreateActorsMovies < ActiveRecord::Migration def self.up create_table :actors_movies, :id => false do |t| t.integer :actor_id, :null => false t.integer :movie_id, :null => false end add_index :actors_movies, [:actor_id, :movie_id], :unique => true end def self.down remove_index :actors_movies, :column => [:actor_id, :movie_id] drop_table :actors_movies end end