summaryrefslogtreecommitdiff
path: root/app/models/tournament.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/tournament.rb')
-rw-r--r--app/models/tournament.rb20
1 files changed, 16 insertions, 4 deletions
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