diff --git a/app/models/match.rb b/app/models/match.rb index 4d6d2bd..dd06693 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -14,8 +14,8 @@ class Match < ActiveRecord::Base def advance_wrestlers if self.w1? && self.w2? - @w1 = Wrestler.find(self.w1) - @w2 = Wrestler.find(self.w2) + @w1 = wrestler1 + @w2 = wrestler2 @w1.advanceInBracket @w2.advanceInBracket self.mat.assignNextMatch @@ -66,7 +66,7 @@ class Match < ActiveRecord::Base end end def weight_max - Weight.find(self.weight_id).max + self.weight.max end def replaceLoserNameWithWrestler(w,loserName) @@ -81,7 +81,7 @@ class Match < ActiveRecord::Base end def poolNumber if self.w1? - Wrestler.find(self.w1).generatePoolNumber + wrestler1.generatePoolNumber end end end diff --git a/app/models/weight.rb b/app/models/weight.rb index 22963ee..1d9229e 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -103,8 +103,7 @@ class Weight < ActiveRecord::Base end def bracket_size - @wrestlers = Wrestler.where(weight_id: self.id) - return @wrestlers.size + wrestlers.size end def pool_bracket_type diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index f0a5533..2f32a2e 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -2,6 +2,7 @@ class Wrestler < ActiveRecord::Base belongs_to :school belongs_to :weight has_one :tournament, through: :weight + has_many :matches, through: :weight attr_accessor :poolNumber before_save do @@ -44,7 +45,7 @@ class Wrestler < ActiveRecord::Base end def allMatches - @matches = Match.where("w1 = ? or w2 = ?",self.id,self.id) + @matches = matches.select{|m| m.w1 == self.id or m.w2 == self.id} return @matches end