diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/team_match_pair.rb | 4 | ||||
-rw-r--r-- | app/models/tournament.rb | 20 | ||||
-rw-r--r-- | app/models/tournament_user_pair.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 4 | ||||
-rw-r--r-- | app/models/user_team_pair.rb | 4 | ||||
-rw-r--r-- | app/models/user_tournament_pair.rb | 4 |
6 files changed, 18 insertions, 22 deletions
diff --git a/app/models/team_match_pair.rb b/app/models/team_match_pair.rb deleted file mode 100644 index 85f8eaa..0000000 --- a/app/models/team_match_pair.rb +++ /dev/null @@ -1,4 +0,0 @@ -class TeamMatchPair < ActiveRecord::Base - belongs_to :team - belongs_to :match -end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 26dec72..44b22f5 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,8 +1,8 @@ class Tournament < ActiveRecord::Base belongs_to :game has_many :matches - has_many :user_tournament_pairs - has_many :users, :through => :user_tournament_pairs + has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments" + has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments" def open? return true @@ -16,7 +16,19 @@ class Tournament < ActiveRecord::Base unless joinable_by?(user) return false end - pair = UserTournamentPair.new(tournament: self, user: user) - return pair.save + players<<user end + + def setup + num_teams = (self.users.count/self.players_per_team).floor + num_matches = num_teams - 1 + for i in 0..num_matches + self.matches.create(name: "Match #{i}") + end + #self.players.each_slice(num_teams) do |team_players| + # Team.new(users: team_players) + #end + end + + end diff --git a/app/models/tournament_user_pair.rb b/app/models/tournament_user_pair.rb deleted file mode 100644 index eb4e9c5..0000000 --- a/app/models/tournament_user_pair.rb +++ /dev/null @@ -1,4 +0,0 @@ -class TournamentUserPair < ActiveRecord::Base - belongs_to :tournament - belongs_to :user -end diff --git a/app/models/user.rb b/app/models/user.rb index bad7f7b..ff212e4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ class User < ActiveRecord::Base - has_many :user_tournament_pairs - has_many :tournaments, :through => :user_tournament_pairs + has_and_belongs_to_many :tournaments_played, class_name: "Tournament", foreign_key: "tournament_id", join_table: "players_tournaments" + has_and_belongs_to_many :tournaments_hosted, class_name: "Tournament", foreign_key: "tournament_id", join_table: "hosts_tournaments" before_save { self.email = email.downcase } before_save { self.user_name = user_name } diff --git a/app/models/user_team_pair.rb b/app/models/user_team_pair.rb deleted file mode 100644 index c55dc2e..0000000 --- a/app/models/user_team_pair.rb +++ /dev/null @@ -1,4 +0,0 @@ -class UserTeamPair < ActiveRecord::Base - belongs_to :user - belongs_to :team -end diff --git a/app/models/user_tournament_pair.rb b/app/models/user_tournament_pair.rb deleted file mode 100644 index b2676e5..0000000 --- a/app/models/user_tournament_pair.rb +++ /dev/null @@ -1,4 +0,0 @@ -class UserTournamentPair < ActiveRecord::Base - belongs_to :user - belongs_to :tournament -end |