diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-03-06 22:14:58 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-03-06 22:14:58 -0500 |
commit | 4a91128f6fe20d95b6692abaa5e6c4dc92418b46 (patch) | |
tree | 467ae35d1ba927c734366f47339c62ac80f4bb56 /app/models | |
parent | 9493275dbb5c59cfe571c48a8ff76d5b1a723d6a (diff) |
fix the has_and_belongs_to_many relations
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/tournament.rb | 7 | ||||
-rw-r--r-- | app/models/user.rb | 4 |
2 files changed, 5 insertions, 6 deletions
diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 0510864..aa22afa 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_and_belongs_to_many :players, class_name: "User", join_table: "tournaments_players" - has_and_belongs_to_many :hosts, class_name: "User", join_table: "tournaments_hosts" + 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,6 @@ class Tournament < ActiveRecord::Base unless joinable_by?(user) return false end - pair = UserTournamentPair.new(tournament: self, user: user) - return pair.save + players<<user end end diff --git a/app/models/user.rb b/app/models/user.rb index 0a226e5..ff212e4 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", join_table: "tournaments_players" - has_and_belongs_to_many :tournaments_hosted, class_name: "Tournament", join_table: "tournaments_hosts" + 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 } |