[Zope-dev] RFC: RelationAware class for relations betweenobjects
Shane Hathaway
shane@zope.com
Tue, 29 Apr 2003 14:28:10 -0400
Leonardo Rochael Almeida wrote:
> In Zope and in Python we already have RELATIONs, by putting a bunch of
> similar objects in a list or as children of a Folder or ObjectManager.
> We still don't have a convenient way to express RELATIONSHIPs, and this
> thread looks very promising in this regard, but the APIs being discussed
> here are already calling RELATIONSHIPs RELATIONs and this worries me a
> little.
I like that distinction. We should stick to it.
To clarify, the API used by the example I posted formalizes relations
with the intent of making relationships easy to create and discover. A
goal that's important to me is the ability to infer new relationships
from an existing data set, which is relatively easy to do with formal
relations. Here is the example with some revisions to demonstrate more
of what I have in mind:
class IRegistration (Interface):
student = Attribute('student', 'A Student object')
course = Attribute('course', 'A Course object')
term = Attribute('term', 'A Term object')
registrations = RelationBuilder(IRegistration)
current_registrations = registrations.view(filter=CurrentTermFilter())
class Registration (Persistent):
implements(IRegistration)
def __init__(self, student, course, term):
self.student = student
self.course = course
self.term = term
class Term (Persistent):
def __init__(self, name):
self.name = name
class Student (Persistent):
current_courses = current_registrations.view(
match='student', select='course')
all_courses = registrations.view(
match='student', select='course')
class Course (Persistent):
current_students = current_registrations.view(
match='course', select='student')
all_students = registrations.view(
match='course', select='student')
*shrug* I know how to implement this, but I don't know if it's a good
idea. Thoughts?
Shane