# Modelling question

**URL:** <https://www.ruby-forum.com/t/modelling-question/184801>\
**Category:** Rails\
**Created:** [March 8, 2010, 10:03pm UTC](https://www.ruby-forum.com/t/modelling-question/184801 "2010-03-08T22:03:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [March 8, 2010, 10:03pm UTC](https://www.ruby-forum.com/t/modelling-question/184801/1 "2010-03-08T22:03:48Z")

</div>

Hi,

I have these 3 models:  
City :name  
Product :name  
city\_preference :city\_id, :product\_id, :min, :max

How do i create the associations between these tables?  
Best  
Greg

---

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [March 8, 2010, 10:28pm UTC](https://www.ruby-forum.com/t/modelling-question/184801/2 "2010-03-08T22:28:07Z")

</div>

Look up has\_many and belongs\_to

---

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [March 8, 2010, 10:33pm UTC](https://www.ruby-forum.com/t/modelling-question/184801/3 "2010-03-08T22:33:23Z")

</div>

On 8 March 2010 21:03, Greg Ma [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I have these 3 models:  
> City :name  
> Product :name  
> city\_preference :city\_id, :product\_id, :min, :max
> 
> How do i create the associations between these tables?

Have a look at the rails guide on ActiveRecord Associations at  
[http://guides.rubyonrails.org](http://guides.rubyonrails.org). Also Getting Started, Debugging and  
the others if you have not already worked through them.

Also don’t think about tables first, think about the real world  
objects you are modeling and what there relationships and attributes  
are. That will then allow you to define the tables and associations.

Colin
