diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 46e28f4..ff58cf7 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,4 +1,8 @@ # frozen_string_literal: true class Tournament < ApplicationRecord + validates :name, presence: true + validates :code, presence: true, uniqueness: true + + belongs_to :user end diff --git a/app/models/user.rb b/app/models/user.rb index ef5c4d4..b24614f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,4 +7,6 @@ class User < ApplicationRecord include DeviseTokenAuth::Concerns::User validates :username, presence: true, uniqueness: true + + has_many :tournaments, dependent: :destroy end diff --git a/db/migrate/0000_create_schema.rb b/db/migrate/0000_create_schema.rb index f8feccb..37821cf 100644 --- a/db/migrate/0000_create_schema.rb +++ b/db/migrate/0000_create_schema.rb @@ -40,11 +40,14 @@ class CreateSchema < ActiveRecord::Migration[5.2] end create_table :tournaments do |t| - t.string :name - t.string :code + t.string :name, null: false + t.string :code, null: false t.string :description t.boolean :public, default: true + # relation to owner + t.belongs_to :user, index: true, foreign_key: true, null: false + t.timestamps end