[Zope-dev] PROPOSAL: ZODB Relationships
Max M
maxm@mxm.dk
Fri, 09 May 2003 11:39:16 +0200
roche@upfrontsystems.co.za wrote:
>We finally have a proposal out for ZODB relationships. This proposal
>presents an API for relationships, summarises ideas and contributions
>from a lot of people and was fuelled by the recent discussions about
>relationships on Zope3-dev and Zope-dev.
>
> http://www.zope.org/Members/upfront/ZODBRelationships
>
>Your comments would be appreciated.
>
I have found the need for an API change. This:
def get(obj):
"""
Returns all objects related to this object as a set, or an empty set.
"""
Should really be changed to;
def get(objects):
"""
Returns all objects related to these object as a set, or an empty set.
"""
Frequently I need to get an aggregated list of relations. Ie. if I want
to find all the student in a "department" I first find all the courses
in that department, and then I find all the unique students. For things
like that I have found that I very often use this idiom:
unique = {}
for obj in objects:
result = self.relations.students_class.get(obj)
for r in result:
unique[tuple(r.getPhysicalPath())] = r
aggregated = unique.items()
It would be much easier to be able to pass a sequence and just use:
aggregated = self.relations.students_class.get(objects)
It is also consistent with the use of list and objects as passed to
relate etc.
regards Max M