[Zope-dev] RFC: RelationAware class for relations betweenobjects

Oliver Bleutgen myzope@gmx.net
Thu, 01 May 2003 18:00:35 +0200


Shane Hathaway wrote:
> Max M wrote:
> 
>>> - Developers should have the *option* of using relationships directly 
>>> in their classes, with a Pythonic API. 
>>
>>
>> I think that should be working on top a general relationship service.
> 
> 
> I agree.  It would be helpful, though, to identify a use case that 
> describes why both you and I believe that relationships must be stored 
> in a centralized location.  I'd like this to justify a particular 
> implementation I'm considering (see below.)

To add some perspective from the "outside", i.e. a Zope 2 product 
developer, I really can't see why relationships should be stored this way.
First, it feels so "un-objectoriented". If I want to know from an object 
to which other objects it relates to (I am implying here that 
relationships are directed), I want to ask the object, not some 
centralized location.

Second, there's the point of scaling. Let's say I have an online shop 
with 100 categories, and 10000 items for sale. Say I want to place items 
in more than one category. I'd use relations (category -> item). But now 
the central "relationship" database will hold up to one million items, 
while storing the relationships in the categories will only go up to 
10000. And that is IMO the more typical use case.

While you can search the central location for relationships, the same 
could also be achieved by combining the local storage of relationships 
with maybe a special index for (Z)Catalog.

I also don't see how one could get an (A,B) relationship implemented in 
Zope 2 without B being RelationshipAware (hah ;)), no matter where the 
relationships are stored. Depending on the key used for B, a lot of 
problems can occur. As it was talked about the problem with "moving" 
objects, I assume the path to an object could be the used as a key. This 
gets interesting when on deletes B and adds another B for instance.

Another question, what happens if I export a subtree with objects to 
another zope? With the relationships are stored as attributes to the 
objects, I'm able to to at least keep some of the relationship 
information, maybe I just have to verify which relations are still valid 
and delete the ones which point to non-existing objects. What would I do 
in the centralized case?

In short, as a developer for zope 2, I'd like to see relations 
implemented in their most basic form, that is as a possibility to do a 
1:n mapping between one object and others.

cheers,
oliver