created user model
This commit is contained in:
parent
f3b67b0800
commit
ffc09cabc4
@ -1,6 +1,7 @@
|
||||
class Article < ApplicationRecord
|
||||
include Visible
|
||||
|
||||
belongs_to: :user
|
||||
has_many :comments, dependent: :destroy
|
||||
|
||||
validates :title, presence: true
|
||||
|
@ -1,3 +1,5 @@
|
||||
class User < ApplicationRecord
|
||||
has_many :articles, dependent: :destroy
|
||||
|
||||
has_secure_password
|
||||
end
|
||||
|
@ -1,6 +1,9 @@
|
||||
class CreateUsers < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :users do |t|
|
||||
t.string :username
|
||||
t.string :email
|
||||
t.string :password_digest
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
@ -0,0 +1,5 @@
|
||||
class AddUserReferenceToArticles < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_reference :articles, :user, foreign_key: true
|
||||
end
|
||||
end
|
13
db/schema.rb
generated
13
db/schema.rb
generated
@ -10,13 +10,15 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_08_07_123956) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_08_07_145348) do
|
||||
create_table "articles", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.text "body"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "status"
|
||||
t.integer "user_id"
|
||||
t.index ["user_id"], name: "index_articles_on_user_id"
|
||||
end
|
||||
|
||||
create_table "comments", force: :cascade do |t|
|
||||
@ -29,5 +31,14 @@ ActiveRecord::Schema[7.1].define(version: 2024_08_07_123956) do
|
||||
t.index ["article_id"], name: "index_comments_on_article_id"
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "username"
|
||||
t.string "email"
|
||||
t.string "password_digest"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_foreign_key "articles", "users"
|
||||
add_foreign_key "comments", "articles"
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user