Add owner method to Stage, Group and Match
This commit is contained in:
parent
be24b1bc39
commit
1b9db61c22
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue