Luke Opperman | 2 May 2005 16:57

Re: Uni-directional links

Quoting Rajeev J Sebastian <rajeev_jsv <at> dinamis.com>:

> Hi,
>
> How would I implement the following scheme:
>
> class Person:
>  def __init__(self):
>   ##holds Memo objects
>   self.memos = []
>
> class Bill:
>  def __init__(self):
>   ##holds Memo objects
>   self.memos = []
>
> class Memo:
>  def __init__(self):
>   self.text = ""

 From a relational viewpoint, I might represent this with an intersection table
for PersonMemo and BillMemo - a RelatedJoin in SQLObject. The only downside to
this is that by default it would be an n-to-n relationship, allowing a Memo to
be associated with both a Bill and a Person or multiple people/bills. You
could constrain this in code if necessary (overriding
Person.addMemo/Bill.addMemo to check the given memo object,  for instance).

But there has to be a key somewhere - I've just moved it into the intersection
tables with this design - avoids either/or NULLs in Memo this way, but still
doesn't exactly represent your intentions.
(Continue reading)


Gmane