From 2866c93aec9da9a74bf54bc695c5b37109aefd55 Mon Sep 17 00:00:00 2001 From: jcwimer Date: Wed, 20 Jan 2016 17:52:21 +0000 Subject: [PATCH] Destroy matches if a school wrestler or weight is destroyed --- app/models/school.rb | 4 ++++ app/models/tournament.rb | 3 +++ app/models/wrestler.rb | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/app/models/school.rb b/app/models/school.rb index a29eabd..598eb77 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -6,6 +6,10 @@ class School < ActiveRecord::Base validates :name, presence: true + before_destroy do + self.tournament.destroyAllMatches + end + #calculate score here def pageScore if self.score == nil diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 6fe5f1d..490812f 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -46,6 +46,9 @@ class Tournament < ActiveRecord::Base def destroyAllMatches matches.destroy_all end + if Rails.env.production? + handle_asynchronously :destroyAllMatches + end def matchesByRound(round) matches.joins(:weight).where(round: round).order("weights.max") diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index a41da48..081ab82 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -8,6 +8,11 @@ class Wrestler < ActiveRecord::Base validates :name, :weight_id, :school_id, presence: true + before_destroy do + self.tournament.destroyAllMatches + self.weight.resetAllSeeds + end + before_create do self.tournament.destroyAllMatches end