[Zope3-dev] zwiki: performance of findChildren()

Shane Hathaway shane@zope.com
Fri, 25 Apr 2003 15:00:29 -0400


Jeremy Hylton wrote:
> On Fri, 2003-04-25 at 12:12, Shane Hathaway wrote:
>>So, Jeremy, I'd like to understand this idea of relations better.  What 
>>would it look like to the application programmer?
> 
> 
> I'd like to understand it better too.  I think the idea is to represent
> relations between two objects using a BTree index with properties on the
> object themselves to keep a natural Python API.  Here's an example I've
> invented to have something concrete to talk about.

I fixed the typos according to what I assume you meant. ;-)


class SoftwareProject(Persistent):

     def __init__(self, name):
         self.name = name
         self.developers = rel

class Developer(Persistent):

     def __init__(self, name):
         self.name = name
         self.projects = rel

rel = relation(Developer, SoftwareProject)

zope3 = SoftwareProject("Zope3")
jim = Developer("Jim Fulton")
stevea = Developer("Steve Alexander")

zope3.developers.add(jim)
zope3.developers.add(stevea)
assert zope3 in stevea.projects



This is a nice example.  People have been craving for something like 
this.  It seems to make many-to-many relationships easy, but I have a 
lot of questions.  I think I'll spend some time building a little 
application based on this idea and find out where I get stuck.

I notice that the relation object has to know the class of the object 
through which it is accessed.  When you access the relation through a 
SoftwareProject, the relation should act like a container of Developers, 
and when you access it through a Developer, it has to act like a 
container of SoftwareProjects.  To make that knowledge available, maybe 
relations are descriptors.

Also, in the example, "rel" is a global.  You wouldn't want "rel" to be 
a simple persistent object, since that would make all threads share the 
same persistent object.

Shane