class Team < ApplicationRecord has_many :user_teams, dependent: :destroy has_many :users, through: :user_teams has_many :matches, dependent: :destroy has_one :youtube_credential, dependent: :destroy has_one :subscription, dependent: :destroy has_many :recordings, dependent: :destroy has_many :team_invitations, dependent: :destroy validates :name, presence: true def entitlements @entitlements ||= Teams::Entitlements.new(self) end def owner user_teams.find_by(role: "owner")&.user end end