mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-16 21:11:38 +00:00
Had to convert all Matchups to hash and back to objects for serialization
This commit is contained in:
@@ -4,7 +4,7 @@ class Tournament < ActiveRecord::Base
|
|||||||
has_many :matches, dependent: :destroy
|
has_many :matches, dependent: :destroy
|
||||||
has_many :mats, dependent: :destroy
|
has_many :mats, dependent: :destroy
|
||||||
attr_accessor :upcomingMatches, :unfinishedMatches
|
attr_accessor :upcomingMatches, :unfinishedMatches
|
||||||
serialize :matchups_array, Array
|
serialize :matchups_array
|
||||||
|
|
||||||
def unfinishedMatches
|
def unfinishedMatches
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ class Tournament < ActiveRecord::Base
|
|||||||
|
|
||||||
def upcomingMatches
|
def upcomingMatches
|
||||||
if self.matchups_array?
|
if self.matchups_array?
|
||||||
return self.matchups_array
|
return matchupHashesToObjects(self.matchups_array)
|
||||||
else
|
else
|
||||||
return generateMatchups
|
return generateMatchups
|
||||||
end
|
end
|
||||||
@@ -32,8 +32,8 @@ class Tournament < ActiveRecord::Base
|
|||||||
@upcomingMatches = weight.generateMatchups(@matches)
|
@upcomingMatches = weight.generateMatchups(@matches)
|
||||||
end
|
end
|
||||||
@upcomingMatches = assignBouts(@upcomingMatches)
|
@upcomingMatches = assignBouts(@upcomingMatches)
|
||||||
#self.matchups_array = @upcomingMatches
|
self.matchups_array = matchupObjectsToHash(@upcomingMatches)
|
||||||
#self.save
|
self.save
|
||||||
return @upcomingMatches
|
return @upcomingMatches
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -42,6 +42,43 @@ class Tournament < ActiveRecord::Base
|
|||||||
@matches = @bouts.assignBouts(matches)
|
@matches = @bouts.assignBouts(matches)
|
||||||
return @matches
|
return @matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def matchupObjectsToHash(matches)
|
||||||
|
array_of_hashes = []
|
||||||
|
matches.each do |m|
|
||||||
|
@matchHash = Hash.new
|
||||||
|
@matchHash["w1"] = m.w1
|
||||||
|
@matchHash["w2"] = m.w2
|
||||||
|
@matchHash["round"] = m.round
|
||||||
|
@matchHash["weight_id"] = m.weight_id
|
||||||
|
@matchHash["boutNumber"] = m.boutNumber
|
||||||
|
@matchHash["w1_name"] = m.w1_name
|
||||||
|
@matchHash["w2_name"] = m.w2_name
|
||||||
|
@matchHash["bracket_position"] = m.bracket_position
|
||||||
|
@matchHash["bracket_position_number"] = m.bracket_position_number
|
||||||
|
array_of_hashes << @matchHash
|
||||||
|
end
|
||||||
|
return array_of_hashes
|
||||||
|
end
|
||||||
|
|
||||||
|
def matchupHashesToObjects(matches)
|
||||||
|
array_of_objects = []
|
||||||
|
matches.each do |m|
|
||||||
|
@match = Matchup.new
|
||||||
|
@match.w1 = m["w1"]
|
||||||
|
@match.w2 = m["w2"]
|
||||||
|
@match.round = m["round"]
|
||||||
|
@match.weight_id = m["weight_id"]
|
||||||
|
@match.boutNumber = m["boutNumber"]
|
||||||
|
@match.w1_name = m["w1_name"]
|
||||||
|
@match.w2_name = m["w2_name"]
|
||||||
|
@match.bracket_position = m["bracket_position"]
|
||||||
|
@match.bracket_position_number = m["bracket_position_number"]
|
||||||
|
array_of_objects << @match
|
||||||
|
end
|
||||||
|
return array_of_objects
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user