diff --git a/app/models/group.rb b/app/models/group.rb index 1b99378..b9bac6a 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -5,6 +5,8 @@ class Group < ApplicationRecord has_many :matches, dependent: :destroy has_many :group_scores, dependent: :destroy + delegate :owner, to: :stage + def teams matches.map(&:teams).flatten.uniq end diff --git a/app/models/match.rb b/app/models/match.rb index 6c3eee8..8ab9756 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -15,6 +15,10 @@ class Match < ApplicationRecord match_scores.map(&:team).flatten.uniq end + def owner + stage ? stage.owner : group.owner + end + private def stage_xor_group diff --git a/app/models/stage.rb b/app/models/stage.rb index 48ad20d..e1aa980 100644 --- a/app/models/stage.rb +++ b/app/models/stage.rb @@ -5,6 +5,8 @@ class Stage < ApplicationRecord has_many :matches, dependent: :destroy has_many :groups, dependent: :destroy + delegate :owner, to: :tournament + def teams return matches.map(&:teams).flatten.uniq unless matches.size.zero?