2009/8/1 Andrew Pace <[email protected]>:
>
> I have a three table construct.  A "Users" table.  Users have a one-to-
> one relationship with a "Carts" table for saving the contents of a
> shopping cart to the DB.  I have a "Products" table for holding
> product information.  The Carts have a many-to-many relationship with
> the Products.  (One cart might have more than one product in it, and
> one product might be represented in more than one user's cart.)
>
> What association would be best to describe this relationship?  And
> what would the migrations and model statements look like?
>

Possibly:
User has_one Cart
Cart belongs_to User, has_and_belongs_to_many Products
Product has_and_belongs_to_many Carts

See the rails guides Getting Started and ActiveRecord Relationships at
http://guides.rubyonrails.org/ for more details.

Colin

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to