Add teams method to group,match,stage
It returns the unique teams that compete within the object
This commit is contained in:
parent
7eadc27c39
commit
cb158fda06
|
|
@ -4,4 +4,8 @@ class Group < ApplicationRecord
|
|||
belongs_to :stage
|
||||
has_many :matches, dependent: :destroy
|
||||
has_many :group_scores, dependent: :destroy
|
||||
|
||||
def teams
|
||||
matches.map{ |m| m.teams}.flatten.uniq
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ class Match < ApplicationRecord
|
|||
|
||||
validate :stage_xor_group
|
||||
|
||||
def teams
|
||||
match_scores.map{ |ms| ms.team}.flatten.uniq
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def stage_xor_group
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ class Stage < ApplicationRecord
|
|||
has_many :groups, dependent: :destroy
|
||||
|
||||
def teams
|
||||
groups.map{|g| g.matches.map{ |m| m.match_scores.map{ |ms| ms.team}}}.flatten.uniq
|
||||
groups.map{|g| g.teams}.flatten.uniq
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue