[Zope-dev] PROPOSAL: ZODB Relationships

Jean Jordaan jean@upfrontsystems.co.za
Fri, 09 May 2003 13:05:33 +0200


>>             student_courses = Relationship()
>>
>> So you can examine the relationship you are interested in by finding
>> it in the repository for relationships (eg. in a folder) as:
>>
>>   <relationshipfolder>.student_courses
>>   <relationshipfolder>.course_teachers
> 
> Well, the above code doesn't create that attribute...

Indeed, written out properly it would be something like:

   student_courses = Relationship()
   <relationshipfolder>._setObject('student_courses', student_courses)

> The above code also is bad because it allows anybody to kill all stored 
> relations by just creating a new Relations object and assigning that to 
> the object attribute. 

Then don't do that ..

> It's then better to have an API more like
> 
>     <storage>.addRelation(relid, objecta, objectb)

You could still delete the storage if you wanted to kill all stored
relations, couldn't you?

> class course:
>     def __init__(self):
>         relstorage = GetRelationshipStorage()
>         relstorage.CreateRelationship('students')
> 
>     def assignStudent(self, student):
>         relstorage = GetRelationshipStorage()
>         relstorage.addRelationship('students', self, student)

According to the proposal, you first create a relationship, and
then you add a view of that relationship (either a ComputedAttribute
or a descriptor) to your class, if you want to access the relationship
as an attribute on your class.

If the relationship repository is not global, the view would
have to acquire it.

-- 
Jean Jordaan
http://www.upfrontsystems.co.za