diff --git a/app/models/group.rb b/app/models/group.rb index 39cba55..1b99378 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -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(&:teams).flatten.uniq + end end diff --git a/app/models/match.rb b/app/models/match.rb index 0eb0c14..6c3eee8 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -11,6 +11,10 @@ class Match < ApplicationRecord validate :stage_xor_group + def teams + match_scores.map(&:team).flatten.uniq + end + private def stage_xor_group diff --git a/app/models/stage.rb b/app/models/stage.rb index b43d80c..64b788e 100644 --- a/app/models/stage.rb +++ b/app/models/stage.rb @@ -4,4 +4,8 @@ class Stage < ApplicationRecord belongs_to :tournament has_many :matches, dependent: :destroy has_many :groups, dependent: :destroy + + def teams + groups.map(&:teams).flatten.uniq + end end