BigLug has asked for the wisdom of the Perl Monks concerning the following question:
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:
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.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
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?"
|
|---|