From 1fdc292aaa9dce6ed3cef5203bee1ca8d3fbb0d4 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Wed, 24 Apr 2019 12:00:17 +0200 Subject: [PATCH] Add method to get all teams within a stage --- app/models/stage.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/stage.rb b/app/models/stage.rb index b43d80c..5e1d9d0 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{|g| g.matches.map{ |m| m.match_scores.map{ |ms| ms.team}}}.flatten.uniq + end end