I'm using Class::DBI for the first time for a project I'm working on at the moment. I've tinkered in the past but I have a new question for you. One that I can't find in the docs.

I have a many-to-many relationship. The docs explain how to do this and it makes some sense. However, when I'm not using Class::DBI it's easy to created a conditional many-to-many relationship. One that has an expiry. Consider this data:

User | Group | Expires ------+-------+------------ 1 | 1 | 2004-11-11 2 | 1 | 2005-01-01 3 | 1 | 2003-12-31 3 | 2 | 2005-01-01 SELECT User FROM Subscription WHERE Group = 1 AND Expires > now(); # 1, 2 SELECT Group FROM Subscription WHERE User = 3 AND Expires > now(); # 2
In an ordinary many-to-many, user 1 is in group 1, user 2 is in group 1 and user 3 is in both 1 and 2. However in this case user 3 should not be in group 1. His membership in that group has expired.

Wise monks, using Class::DBI how would I make that happen?

Note 1: There's also a live date -- the date at which point the subscription starts. However I felt that once I get the expiry worked out, the start date will be easy.

Note 2: When creating a new subscription, the old one should not be overwritten. Should User 3 become a member of group 1 at some later stage, then it would be a new record in the subscription table. This will allow historic queries like "Who was in group 1 on 2004-01-01?"


Cheers!
Rick
If this is a root node: Before responding, please ensure your clue bit is set.
If this is a reply: This is a discussion group, not a helpdesk ... If the discussion happens to answer a question you've asked, that's incidental.

In reply to Conditional many to many relationships with Class::DBI by BigLug

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.