From 1b9db61c22820c92b7ca1313e501de598e5e3fd2 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Tue, 7 May 2019 15:19:15 +0200 Subject: [PATCH] Add owner method to Stage, Group and Match --- app/models/group.rb | 2 ++ app/models/match.rb | 4 ++++ app/models/stage.rb | 2 ++ 3 files changed, 8 insertions(+) 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?