Complete Lesson 35 Part 1
This commit is contained in:
parent
76b2738b01
commit
29ac49b40d
@ -1,7 +1,7 @@
|
|||||||
class Review < ApplicationRecord
|
class Review < ApplicationRecord
|
||||||
belongs_to :movie
|
belongs_to :movie
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
validates :name, presence: true
|
|
||||||
validates :comment, length: { minimum: 4 }
|
validates :comment, length: { minimum: 4 }
|
||||||
validates :stars, numericality: { greater_than_or_equal_to: 1, less_than_or_equal_to: 5 }
|
validates :stars, numericality: { greater_than_or_equal_to: 1, less_than_or_equal_to: 5 }
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
class User < ApplicationRecord
|
class User < ApplicationRecord
|
||||||
has_secure_password
|
has_secure_password
|
||||||
|
|
||||||
|
has_many :reviews, dependent: :destroy
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates :email, presence: true, format: { with: /\S+@\S+/ }, uniqueness: { case_sensitive: false }
|
validates :email, presence: true, format: { with: /\S+@\S+/ }, uniqueness: { case_sensitive: false }
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
class MakeReviewsAJoinTable < ActiveRecord::Migration[7.0]
|
class MakeReviewsAJoinTable < ActiveRecord::Migration[7.0]
|
||||||
def change
|
def change
|
||||||
|
remove_column :reviews, :name, :string
|
||||||
|
add_column :reviews, :user_id, :integer
|
||||||
|
Review.delete_all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
4
db/schema.rb
generated
4
db/schema.rb
generated
@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.0].define(version: 2023_09_27_121300) do
|
ActiveRecord::Schema[7.0].define(version: 2023_09_27_122117) do
|
||||||
create_table "movies", force: :cascade do |t|
|
create_table "movies", force: :cascade do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.string "rating"
|
t.string "rating"
|
||||||
@ -25,12 +25,12 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_27_121300) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
create_table "reviews", force: :cascade do |t|
|
create_table "reviews", force: :cascade do |t|
|
||||||
t.string "name"
|
|
||||||
t.integer "stars"
|
t.integer "stars"
|
||||||
t.text "comment"
|
t.text "comment"
|
||||||
t.integer "movie_id", null: false
|
t.integer "movie_id", null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.integer "user_id"
|
||||||
t.index ["movie_id"], name: "index_reviews_on_movie_id"
|
t.index ["movie_id"], name: "index_reviews_on_movie_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user