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