[Zope] Advice on a One-to-Many relationship for Zope Object

Johan Carlsson johanc@easypublisher.com
Thu, 17 Jul 2003 07:38:03 +0200


Norman Khine wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi,
> I am trying to get my head arround on how to build a registration
> form, that has a one-to-many relationship. Basically, what I am
> trying to do is to have two "tables" one listing business_addresses
> and on the other "table" to list all emplolyees for that business,
> thus creating a one-to-many relation between the business_address
> object and the employees.
> 
> If anyone can point me on how to achieve this, I'll be most greatfull

Here's my 25 cents:

Can't you just use a list in the "one" object with referense by object 
paths to the "many" objects.

You might also need an API that can fetch the related object, add and
remove related objects and a mechanism that updates the object paths
if the objects are moved.

If you don't want to use object paths you need to create a unique id 
generator that gives all object a unique id.
(Some thing like this: 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/163604)	

Or you might want to use intergers, which would be exective if
you ever want to use join and unions etc. from IIBTree.

I you don't use paths you need a ZCatalog (or similar central registry)
to map UID to location.

The many list can also be indexed by the ZCatalog as a keyword index,
which lets you query for things like all object refering to object B.

Many-to-many relations could be implented in the same way, with on list
at each side, but a link would only be valid if both sides have the link
so you need an API that enforces that requirement.


-- 
Johan Carlsson          Tel: + 46 8 31 24 94
Colliberty              Mob: + 46 70 558 25 24
Torsgatan 72            Email: johanc@easypublisher.com
SE-113 37 STOCKHOLM