# A little help with associations

**URL:** <https://www.ruby-forum.com/t/a-little-help-with-associations/120716>\
**Category:** Rails\
**Created:** [November 20, 2007, 1:32am UTC](https://www.ruby-forum.com/t/a-little-help-with-associations/120716 "2007-11-20T01:32:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cantankerous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e95f7d/32.png) [@cantankerous](https://www.ruby-forum.com/u/cantankerous)\
**Post date:** [November 20, 2007, 1:32am UTC](https://www.ruby-forum.com/t/a-little-help-with-associations/120716/1 "2007-11-20T01:32:07Z")

</div>

I know this is an easy question for a software developer but I’m new  
to this so I’d really appreciate a little help in designing  
associations. The basic models I have created are listed below but I’m  
having a little trouble in linking the location (addresses)  
information to where it is needed in each of the other models. This is  
illustrated in two places:

Linking events to a location

My basic idea (from reading the various web posts - thanks) is that  
rather than using has\_and\_belongs\_to\_many I need to create another  
model called venues which links a location to an event, however all of  
the online examples seem to have a many-many relationship whereas I  
want to create a linking model where a location can have many venues  
(think the screens in a cinema) but an event can have only one venue.  
How to I write this?

Contact details

I then want to store two additional sets of contact details for each  
event, the primary contact (contact details public) and the event  
owner (private for admin use). Again, do I need to create some form of  
linking model (to store the type of contact) or can I just use habtm?

Event\_lists

- Have a default venue (which has a location)
- Have events (each has a location)
- Has an owner (has an address - a location)
- Has a primary contact (has an address - a location)

Events

- Have a venue (which has a location)
- Have a primary contact (a person who has a location for this event)
- Have an owner (a person who has a location)

Location

- Has an address
- Has a latitude and longitude

People

- Have an address (which is a link to the location table)

---

<div class="post-metadata">

**Author:** ![cantankerous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e95f7d/32.png) [@cantankerous](https://www.ruby-forum.com/u/cantankerous)\
**Post date:** [November 22, 2007, 7:52am UTC](https://www.ruby-forum.com/t/a-little-help-with-associations/120716/2 "2007-11-22T07:52:15Z")

</div>

This is how I’d do it… yachtman

Table locations { has\_many :venues, has\_many :contacts }

- id
- name
- address
- latitude
- longitude

Table contacts { belongs\_to :location, has\_many :contact\_types }

- id
- name
- contact\_type\_id
- location\_id

Table contact\_types { belongs\_to :contact }

- id
- type (owner or contact)

Table venues { belongs\_to :location }

- id
- name
- location\_id

Table events { belongs\_to :venue }

- id
- name
- venue\_id
- primary\_contact\_id
- owner\_id

On Nov 20, 8:31 am, Cantankerous [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
