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 :matches, dependent: :destroy
|
||||||
has_many :group_scores, dependent: :destroy
|
has_many :group_scores, dependent: :destroy
|
||||||
|
|
||||||
|
delegate :owner, to: :stage
|
||||||
|
|
||||||
def teams
|
def teams
|
||||||
matches.map(&:teams).flatten.uniq
|
matches.map(&:teams).flatten.uniq
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,10 @@ class Match < ApplicationRecord
|
||||||
match_scores.map(&:team).flatten.uniq
|
match_scores.map(&:team).flatten.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def owner
|
||||||
|
stage ? stage.owner : group.owner
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def stage_xor_group
|
def stage_xor_group
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ class Stage < ApplicationRecord
|
||||||
has_many :matches, dependent: :destroy
|
has_many :matches, dependent: :destroy
|
||||||
has_many :groups, dependent: :destroy
|
has_many :groups, dependent: :destroy
|
||||||
|
|
||||||
|
delegate :owner, to: :tournament
|
||||||
|
|
||||||
def teams
|
def teams
|
||||||
return matches.map(&:teams).flatten.uniq unless matches.size.zero?
|
return matches.map(&:teams).flatten.uniq unless matches.size.zero?
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue