I am very new to mongodb/mongoid and was wondering about the best way to architect a system that enables users to review products. User and Product will be individual collections. But they both need access to the Review model for displaying the reviews they made on both the User and Product page. Should I create an linked 1 (product) -N (reviews) relationship with an embedded 1(user) - 1(review) relationship? Is this the correct way to do this?
User model
class User
include Mongoid::Document
field :name, type: String
field :email, type: String
embeds_many :reviews, cascade_callbacks: true
end
Product model
class Product
include Mongoid::Document
field :name, type: String
field :price, type: Float
has_many :reviews, dependent: :destroy
end
Review model
class Review
include Mongoid::Document
field :rating, type: Integer
belongs_to :product
embedded_in :user
end
Thanks