It would help in both Programming, and database schema, if you abstract the problem, and think in terms of objects, relationships, properties and KEY fields.

In your case, the primary object is "Person" with a person-ID as a Key field.

The person(object) has a Property - "place".

The person has what appears at first sight, to be 2 "relationships" - whach can be named "assistant" (Can there be more than one ?), and "Boss/Works-for" - again - can there be more than one ?

If you think about it, these relationships define the same thing, and you can avoid a multitude of data integrety and programming erros by using a single relationship for this - I would suggest a "boss" relationship, which is usually a one-to-one. This allows a "boss" to have multiple assistants, but an assistant to have 0 or one boss (The person with zero bosses it the head honcho).

So, your table becomes:

CREATE TABLE Persontbl( person, org,location, boss-link )
And in perl, you can store this as a simple hash with "person" as the key. The "boss-link" will be a ref to another "person", or undef.

     "A closed mouth gathers no feet." --Unknown


In reply to Re: modeling relationships by NetWallah
in thread modeling relationships by punkish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.