I am lost in all the associations options Rails offers.
I have a table for Users
. Those Users
have Products
. This is simply a has_many :products
relationship.
However, I want to provide the users with a list of products. They will choose a number of products and will add a price to it.
So basically, I have
USER 1 -----> PRODUCT 1 ------> PRICE 1 <----.
-----> PRODUCT 2 ------> PRICE 2 |
USER 2 -----> PRODUCT 1 ------> PRICE 3 <----¨
-----> PRODUCT 3 ------> PRICE 4
Should I create three table : User
, Product
and Price
?
And what if the user wants to customize his/her product more with a quantity, need, etc.? Then should I create the following tables instead :User
, Product
and ProductDetail
This way, a user
has_many :product
and a product
has_many :product_detail
.
What is the Rails way of doing this?
I am lost with all the has_many
, has_one
, has_many :through
, etc.