mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-16 13:03:37 +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
|
def advance_wrestlers
|
||||||
if self.w1? && self.w2?
|
if self.w1? && self.w2?
|
||||||
@w1 = Wrestler.find(self.w1)
|
@w1 = wrestler1
|
||||||
@w2 = Wrestler.find(self.w2)
|
@w2 = wrestler2
|
||||||
@w1.advanceInBracket
|
@w1.advanceInBracket
|
||||||
@w2.advanceInBracket
|
@w2.advanceInBracket
|
||||||
self.mat.assignNextMatch
|
self.mat.assignNextMatch
|
||||||
@@ -66,7 +66,7 @@ class Match < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
def weight_max
|
def weight_max
|
||||||
Weight.find(self.weight_id).max
|
self.weight.max
|
||||||
end
|
end
|
||||||
|
|
||||||
def replaceLoserNameWithWrestler(w,loserName)
|
def replaceLoserNameWithWrestler(w,loserName)
|
||||||
@@ -81,7 +81,7 @@ class Match < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
def poolNumber
|
def poolNumber
|
||||||
if self.w1?
|
if self.w1?
|
||||||
Wrestler.find(self.w1).generatePoolNumber
|
wrestler1.generatePoolNumber
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -103,8 +103,7 @@ class Weight < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def bracket_size
|
def bracket_size
|
||||||
@wrestlers = Wrestler.where(weight_id: self.id)
|
wrestlers.size
|
||||||
return @wrestlers.size
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def pool_bracket_type
|
def pool_bracket_type
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ class Wrestler < ActiveRecord::Base
|
|||||||
belongs_to :school
|
belongs_to :school
|
||||||
belongs_to :weight
|
belongs_to :weight
|
||||||
has_one :tournament, through: :weight
|
has_one :tournament, through: :weight
|
||||||
|
has_many :matches, through: :weight
|
||||||
attr_accessor :poolNumber
|
attr_accessor :poolNumber
|
||||||
|
|
||||||
before_save do
|
before_save do
|
||||||
@@ -44,7 +45,7 @@ class Wrestler < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def allMatches
|
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
|
return @matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user