[Zope] [ADVANCED] How do YOU guys do many-to-many in Zope without relational?

seb bacon seb@jamkit.com
Tue, 23 Oct 2001 10:16:16 +0100


* Max M <maxmcorp@worldonline.dk> [011022 22:43]:
> > From: Casey Duncan [mailto:c.duncan@nlada.org]
> 
> > They way to do this is to create a lines property in the student
> > and store
> > the ids of the related subjects there. You use a ZCatalog and a
> > keyword index
> > on this property to quickly find which students belong to which subject.
> 
> Again only if the id's are unique all over the site.

Check out the new PathIndex in 2.4, which would allow you to
reference an object by its path as well as its id.

> > 2. Assign another fixed key as a property (or general attribute) of the
> > subject for use as the unique identifier and don't ever change it for the
> > life of the object.
> 
> There allready exist such a key for each object in the ZODB called the oid,
> but I don't think that it's easy to get at through normal means. I am not
> even shure that it's "allowed" to use it for anything.

You're right: it's not guaranteed to be unique across all ZEO
storages, for example. 

> > You will need to use a ZCatalog to make
> > lookups on this
> > id efficient, but this would allow you to put the object anywhere
> > you like,
> > and rename them without screwing up the relationships. Only
> > deletion would
> > break it.
> 
> Deletion always has a tendency to do this. I need triggers in the ZODB :-)

As Marc mentioned, this should not be a problem with a little
work.  I have never used ZClasses but I believe there is a
ZCatalogable mixin which manages all this for you. 

If not, there are very simple triggers which do what you require
already - the manage_afterDelete and manage_afterAdd hooks. 

seb