mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-12 16:25:41 +00:00
Matchups_array completely removed. I do not know why has_many matches
does not work in tournaments. The solution was to add a matches method.
This commit is contained in:
@@ -1,14 +1,17 @@
|
|||||||
class Tournament < ActiveRecord::Base
|
class Tournament < ActiveRecord::Base
|
||||||
has_many :schools, dependent: :destroy
|
has_many :schools, dependent: :destroy
|
||||||
has_many :weights, dependent: :destroy
|
has_many :weights, dependent: :destroy
|
||||||
has_many :matches, dependent: :destroy
|
has_many :mats, dependent: :destroy
|
||||||
has_many :mats, dependent: :destroy
|
|
||||||
has_many :wrestlers, through: :weights
|
has_many :wrestlers, through: :weights
|
||||||
|
|
||||||
|
|
||||||
|
def matches
|
||||||
|
@matches = Match.where(tournament_id: self.id)
|
||||||
|
end
|
||||||
|
|
||||||
def upcomingMatches
|
def upcomingMatches
|
||||||
if self.matches.nil?
|
if matches.nil?
|
||||||
return self.matches
|
return matches
|
||||||
else
|
else
|
||||||
@matches = generateMatchups
|
@matches = generateMatchups
|
||||||
saveMatchups(@matches)
|
saveMatchups(@matches)
|
||||||
@@ -17,6 +20,7 @@ class Tournament < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def generateMatchups
|
def generateMatchups
|
||||||
|
destroyAllMatches
|
||||||
@matches = []
|
@matches = []
|
||||||
self.weights.map.sort_by{|x|[x.max]}.each do |weight|
|
self.weights.map.sort_by{|x|[x.max]}.each do |weight|
|
||||||
@matches = weight.generateMatchups(@matches)
|
@matches = weight.generateMatchups(@matches)
|
||||||
@@ -34,10 +38,17 @@ class Tournament < ActiveRecord::Base
|
|||||||
|
|
||||||
def saveMatchups(matches)
|
def saveMatchups(matches)
|
||||||
matches.each do |m|
|
matches.each do |m|
|
||||||
|
m.tournament_id = self.id
|
||||||
m.save
|
m.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroyAllMatches
|
||||||
|
matches.each do |m|
|
||||||
|
m.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ class Weight < ActiveRecord::Base
|
|||||||
attr_accessor :pools
|
attr_accessor :pools
|
||||||
|
|
||||||
before_save do
|
before_save do
|
||||||
self.tournament.matchups_array = nil
|
self.tournament.destroyAllMatches
|
||||||
self.tournament.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def pools
|
def pools
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ class Wrestler < ActiveRecord::Base
|
|||||||
attr_accessor :poolNumber
|
attr_accessor :poolNumber
|
||||||
|
|
||||||
before_save do
|
before_save do
|
||||||
self.tournament.matchups_array = nil
|
self.tournament.destroyAllMatches
|
||||||
self.tournament.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150426191006) do
|
ActiveRecord::Schema.define(version: 20150426195714) do
|
||||||
|
|
||||||
create_table "matches", force: :cascade do |t|
|
create_table "matches", force: :cascade do |t|
|
||||||
t.integer "w1"
|
t.integer "w1"
|
||||||
@@ -55,7 +55,6 @@ ActiveRecord::Schema.define(version: 20150426191006) do
|
|||||||
t.string "director_email"
|
t.string "director_email"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.text "matchups_array"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
|
|||||||
3
test/fixtures/tournaments.yml
vendored
3
test/fixtures/tournaments.yml
vendored
@@ -6,8 +6,7 @@ one:
|
|||||||
address: Some Place
|
address: Some Place
|
||||||
director: Jacob Cody Wimer
|
director: Jacob Cody Wimer
|
||||||
director_email: jacob.wimer@gmail.com
|
director_email: jacob.wimer@gmail.com
|
||||||
matchups_array:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ class PoolbracketMatchupsTest < ActionDispatch::IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
def checkForByeInPool(tournament)
|
def checkForByeInPool(tournament)
|
||||||
@matchups = tournament.generateMatchups
|
tournament.upcomingMatches
|
||||||
|
@matchups = tournament.matches
|
||||||
tournament.weights.each do |w|
|
tournament.weights.each do |w|
|
||||||
w.wrestlers.each do |wr|
|
w.wrestlers.each do |wr|
|
||||||
@round = 1
|
@round = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user