diff --git a/app/models/tournament.rb b/app/models/tournament.rb index ff58cf7..d88b5ac 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,8 +1,15 @@ # frozen_string_literal: true +require 'securerandom' + class Tournament < ApplicationRecord validates :name, presence: true validates :code, presence: true, uniqueness: true + has_many :teams, dependent: :destroy belongs_to :user + + after_initialize do |tournament| + tournament.code ||= SecureRandom.hex 3 + end end