# Relations between contact\_person and contact\_business

**URL:** <https://www.ruby-forum.com/t/relations-between-contact-person-and-contact-business/167435>\
**Category:** Rails\
**Created:** [May 7, 2009, 7:11pm UTC](https://www.ruby-forum.com/t/relations-between-contact-person-and-contact-business/167435 "2009-05-07T19:11:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![togo123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9d8465/32.png) [@togo123](https://www.ruby-forum.com/u/togo123)\
**Post date:** [May 7, 2009, 7:11pm UTC](https://www.ruby-forum.com/t/relations-between-contact-person-and-contact-business/167435/1 "2009-05-07T19:11:02Z")

</div>

Hello all,

i am stuck with something.

i have the following situation:

`contacts---|
           |--|0-1|--contact_businesses
           | (either one of booth; business or contact)
           |--|0-1|--contact_people`  
i have a contacts model that either extends to contact\_business or  
contact\_person, depending if its a person or a business.  
now i whant to describe relationships between people and businesses.  
i thought about something like this:

`contacts---|
           |--|0-1|--contact_businesses
           | (either one of booth; business or contact)
           |--|0-1|--contact_people
           |
           |--|0-n|--contact_relations (contact_person_contact_id,
contact_business_contact_id)`  
so contact\_relations would store the contact\_id of the file that is  
create/edited depending if it is a business or a person in  
contact\_business\_contact\_id or contact\_person\_contact\_id and the  
contact\_id of the relation (wich must be the other kind) in the other  
field.  
this would be the way i would do it by hand, if i would have programmed  
this in php. but in ror i dont really know or understand how this is t  
be accomplished.

maybe self joins is the solution  
([Active Record Associations — Ruby on Rails Guides](http://guides.rubyonrails.org/association_basics.html#self-joins)). but  
somehow i dont understand how this works and what table collums i would  
need.

can somebody help me?

thanks a lot,

togo123
