JOIN conditions can be just as complicated as WHERE conditions, but overall having Play and Concert be totally separate things will bite you in the butt repeatedly in the future. The best structure for your database is something like this:

#! pesudocode Entity { id integer PRIMARY KEY, name varchar, ... } Play { id integer PRIMARY KEY REFERENCES Entity(id), director varchar, ... } Concert { id integer PRIMARY KEY REFERENCES Entity(id), start datetime, venue varchar, band varchar, ... } Comment { id integer PRIMARY KEY, entity integer REFERENCES Entity(id), comment_text varchar, ... }

If you need a list of concerts:

SELECT * FROM Concert c INNER JOIN Entity e ON c.id=e.id

If you need a list of plays:

SELECT * FROM Play p INNER JOIN Entity e ON p.id=e.id

If you need a list of comments on plays:

SELECT * FROM Comment k INNER JOIN Entity e ON k.entity=e.id INNER JOIN Play p ON k.entity=p.id

If you need a list of comments on everything:

SELECT * FROM Comment k INNER JOIN Entity e ON k.entity=e.id LEFT JOIN Play p ON k.entity=p.id LEFT JOIN Concert c ON k.entity=c.id

In the long run, you'll benefit a lot from factoring out as much of the common stuff between Concerts, Plays, Paintings, etc into a shared Entity table, then creating additional tables to store Concert-specific, Play-specific, Painting-specific, etc fields. I don't use DBIC, so can't offer specific advice on how to achieve it with that, but from a database design point of view, this is the better way to lay stuff out.

When you want to insert a new play, you insert it into the Entity table first to get its primary key number, then use that number when inserting the additional data into the Play table.


In reply to Re^3: DB: what kind of relationship? by tobyink
in thread DB: what kind of relationship? by bliako

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.