# Associations Question

**URL:** <https://www.ruby-forum.com/t/associations-question/173077>\
**Category:** Rails\
**Created:** [August 1, 2009, 8:22pm UTC](https://www.ruby-forum.com/t/associations-question/173077 "2009-08-01T20:22:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [August 1, 2009, 8:22pm UTC](https://www.ruby-forum.com/t/associations-question/173077/1 "2009-08-01T20:22:15Z")

</div>

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?

Thanks,

Andrew

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [August 1, 2009, 9:20pm UTC](https://www.ruby-forum.com/t/associations-question/173077/2 "2009-08-01T21:20:12Z")

</div>

2009/8/1 Andrew P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 

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/](http://guides.rubyonrails.org/) for more details.

Colin
