[ZODB-Dev] Relationships for ZODB/Zope

Erik A. Dahl edahl@confmon.com
Wed, 24 Apr 2002 09:45:32 -0400


I'm designing a Zope Product / Python library for ZODB that will manage 
relationships between objects in the ZODB.  I wanted to run my musings 
by this group to get some feed back as I think this will be useful to 
many people.  Here is where I am. 

* Relationships are defined a schema.
* Relationship schema has 8 elements: type, cardinality,
    name, and cascadedelete one at each end of the relationship.
* Relationships have three basic actions (add, get, delete). 
    The underlying action will be different based on the cardinality.
* Relationships are bidriectional (i.e. when an action is performed in
    one direction the action in the reverse direction is automatically 
performed)

* Cardinalities are toOne and toMany.
* toOne is a reference to the remote object.
* toMany is a list of references to related objects.

* Relationship names are attributes on their objects.

* Types are Classes (maybe Zope meta-types?) maybe there should be
    a type less relation?

* There will be other actions on a relationship for convenience,
    mostly to perform interesting retrievals like filter based on some 
criteria.

Implementation:
To actually implement this I have in mind three elements: a schema 
object that defines the relationship, an actions object that defines 
methods to perform actions against a relationship (this will be a mix in 
class?) and schema dictionary which stores the schema objects.

Issues:
As per above not sure yet how strict I want to be about typing the ends 
of the relationships.  I'm thinking about different types of relations 
based on the strictness of the end typing.  Possible candidates are type 
by Python Class, by Zope meta-type, and don't worry about it.

The schema dictionary will need to be referenced every time an action is 
taken against a relationship what will be the best way to implement 
this?  At action time we will have local type, local name and remote 
type and we will need to get the full schema object for this relation.  
I have in mind a dictionary that has as key 
"localtype|localname|remotetype".  So for each schema object there will 
be two keys (one for each direction).  Can anyone think of a better way 
to do this?  I hate having the type name strings in there (need to make 
sure they get updated correctly if they change in the schema object!).

Thanks in advance for your input,
-EAD