Relations between contact_person and contact_business


#1

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
(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