mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Trying to remove queries and rely on associations
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user