Skip to content

Instantly share code, notes, and snippets.

@monkbroc
Created April 9, 2015 16:52
Show Gist options
  • Select an option

  • Save monkbroc/8043063cedfaabde828a to your computer and use it in GitHub Desktop.

Select an option

Save monkbroc/8043063cedfaabde828a to your computer and use it in GitHub Desktop.
class CopyTeamUsers < ActiveRecord::Migration
class User < ActiveRecord::Base
has_and_belongs_to_many :teams
has_many :team_user_tmps
has_many :teams_tmp, :through => :team_user_tmps, :source => :team
end
class Team < ActiveRecord::Base
has_and_belongs_to_many :users
has_many :team_user_tmps
has_many :users_tmp, :through => :team_user_tmps, :source => :user
end
class TeamUserTmp < ActiveRecord::Base
belongs_to :team
belongs_to :user
end
def up
Team.find_each do |team|
team.users_tmp = team.users
end
end
def down
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment