Having a bit of trouble conceptually pulling something together in
rails. Imagine the following:
I have Users
I have Products
I have Purchases
A Purchase is simply a user -> product + timestamp relationship. So,
User A bought Proudct B on date X.
Currently, my data model is extremely trivial:
user: id, username, password
products: id, name, price, etc.
purchases: id, user_id, product_id, timestamp
What I’m looking to do is say, “Welcome, User A, you purchased these
products in this time range.” What I’m struggling with is the correct
relationship structure. Obviously a User has_many purchases, but does a
Purchase belong_to a User? I assume so. Does a Purchase have_a
(has_one) User? Does a Purchase have_a (has_one) Product? Do Products
A little direction would be most welcome. Hitting the books now.