Created
May 20, 2013 22:19
-
-
Save vpivo/5616054 to your computer and use it in GitHub Desktop.
Renaming an association
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Game < ActiveRecord::Base | |
has_and_belongs_to_many :users | |
belongs_to :winner, :class_name => "User" | |
end | |
class User < ActiveRecord::Base | |
has_and_belongs_to_many :games | |
validates :name, :uniqueness => true | |
end | |
class GamesUser < ActiveRecord::Base | |
end | |
class CreateUsers < ActiveRecord::Migration | |
def change | |
create_table :users do |t| | |
t.string :name | |
end | |
end | |
end | |
class CreateGames < ActiveRecord::Migration | |
def change | |
create_table :games do |t| | |
t.integer :winner_id | |
t.timestamps | |
end | |
end | |
end | |
class CreateGamesUsers < ActiveRecord::Migration | |
def change | |
create_table :games_users do |t| | |
t.integer :user_id | |
t.integer :game_id | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment