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,6 +1,8 @@
|
|||||||
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 }
|
||||||
end
|
end
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in new issue