Complete Lesson 35 Part 1

main
Simon Quigley 1 year ago
parent 76b2738b01
commit 29ac49b40d

@ -1,7 +1,7 @@
class Review < ApplicationRecord
belongs_to :movie
belongs_to :user
validates :name, presence: true
validates :comment, length: { minimum: 4 }
validates :stars, numericality: { greater_than_or_equal_to: 1, less_than_or_equal_to: 5 }
end

@ -1,5 +1,7 @@
class User < ApplicationRecord
has_secure_password
has_many :reviews, dependent: :destroy
validates :name, presence: true
validates :email, presence: true, format: { with: /\S+@\S+/ }, uniqueness: { case_sensitive: false }

@ -1,4 +1,7 @@
class MakeReviewsAJoinTable < ActiveRecord::Migration[7.0]
def change
remove_column :reviews, :name, :string
add_column :reviews, :user_id, :integer
Review.delete_all
end
end

4
db/schema.rb generated

@ -10,7 +10,7 @@
#
# 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|
t.string "title"
t.string "rating"
@ -25,12 +25,12 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_27_121300) do
end
create_table "reviews", force: :cascade do |t|
t.string "name"
t.integer "stars"
t.text "comment"
t.integer "movie_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.index ["movie_id"], name: "index_reviews_on_movie_id"
end

Loading…
Cancel
Save