I have to deal with large volumes of data of exactly this nature. In my shop we call them assignment records or dated records. Our records typically have a ($id,$keyfield,@other_data,$start_date,$end_date) structure where start_date and end_date are constrained to be in order (start_date<end_date), non null and via trigger based constraints records with the same $keyfield are guaranteed not to overlap in the DB (any update that results in an overlap is rejected by the trigger). We use a long distant date to represent the end_date of "open" assignments, and we state the rule that the start_date is inclusive and the end_date is exclusive (ie the start_date is part of the assignment, the end_date is not, it represents the first second after the assignment.)

This structure allows a much more flexible way of working with this type of data than most of the alternatives I've seen (such as using null to represent open assignments, or to using only a single date column). For instance IMO the query to extract all assignments valid for the month of 2004-11 is not easy to write with the table you have, and probably wont be particularly fast if you do work it out. (This is an operation that is very common for the systems i work on.) With the start_date/end_date mechanism such a query is really very easy to write.

I know this doesnt address your direct question: I'm not a fan or user of Class::DBI at all. I prefer hand rolling my own tools for things like this as I find for the type of database work I do that its both easier to maintain and easier to understand. OTOH I hope my experience with this type of database table is useful to you, especially as I think youll find Note 2 quite difficult to do, and I also wonder what youll do if a user is a member of a group for one month, not a member for the next and then member the following month (ie one/off/on). It seems to me like youll always have a time period where your assignments are wrong.

---
demerphq


In reply to Re: Conditional many to many relationships with Class::DBI by demerphq
in thread 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.