Rails/Relationships/Recommendations

This is basically an example of a n to n relationship. User and Product have n to n relationship. The Purchase is the entity that breaks this relationship into one to many and many to one. So you will have one to many between a user and a purchase and many to one from purchase to product.

You don't need the id in the purchases table because it is a join table and the key consists of the user_id and product_id