Add relation between Tournament and User
This commit is contained in:
parent
683423b06a
commit
d89c24a645
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -7,4 +7,6 @@ class User < ApplicationRecord
|
|||
include DeviseTokenAuth::Concerns::User
|
||||
|
||||
validates :username, presence: true, uniqueness: true
|
||||
|
||||
has_many :tournaments, dependent: :destroy
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue