summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/tournament.rb14
-rw-r--r--app/models/user.rb4
2 files changed, 13 insertions, 5 deletions
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index 44b22f5..fe781e1 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -25,9 +25,17 @@ class Tournament < ActiveRecord::Base
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
+ match_num = 0
+ team_num = 0
+ self.players.each_slice(@tournament.max_players) do |players|
+ matches[match_num].teams[team_num] = Team.new(users: players)
+ if (team_num == 0 and team_num % @tournament.max_teams_per_match == 0)
+ match_num += 1
+ team_num = 0
+ else
+ team_num += 1
+ end
+ end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index ff212e4..bd1a9ac 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,6 +1,6 @@
class User < ActiveRecord::Base
- 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"
+ has_and_belongs_to_many :tournaments_played, class_name: "Tournament", foreign_key: "player_id", join_table: "players_tournaments"
+ has_and_belongs_to_many :tournaments_hosted, class_name: "Tournament", foreign_key: "host_id", join_table: "hosts_tournaments"
before_save { self.email = email.downcase }
before_save { self.user_name = user_name }