Add owner method to Stage, Group and Match

This commit is contained in:
Thor77 2019-05-07 15:19:15 +02:00
parent be24b1bc39
commit 1b9db61c22
No known key found for this signature in database
GPG Key ID: 5051E71B46AA669A
3 changed files with 8 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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?