[Zodb-checkins] CVS: Zope3/src/zodb/query - relation.py:1.1.2.4
Jeremy Hylton
jeremy at zope.com
Mon Apr 28 12:48:22 EDT 2003
Update of /cvs-repository/Zope3/src/zodb/query
In directory cvs.zope.org:/tmp/cvs-serv14534
Modified Files:
Tag: jeremy-query-branch
relation.py
Log Message:
Redefine many2many function as join() + arity() setters.
=== Zope3/src/zodb/query/relation.py 1.1.2.3 => 1.1.2.4 ===
--- Zope3/src/zodb/query/relation.py:1.1.2.3 Fri Apr 25 19:24:24 2003
+++ Zope3/src/zodb/query/relation.py Mon Apr 28 11:48:21 2003
@@ -84,12 +84,13 @@
def setclass(self, cls):
self.cls = cls
- def register(self, other, many):
+ def register(self, other):
+ if self.many is None:
+ raise ValueError, "must define arity first"
# Called by many2many below to establish connection
# between two Relation objects.
self.other = other
self.name = find_attribute_name(other)
- self.many = many
# XXX This is the wrong name! It's the name of the other
# descriptor.
self.attr = "_r_" + self.name
@@ -111,10 +112,17 @@
if r == v.manager:
return name
-def many2many(r1, r2):
- """Connect two Relations in a many-to-many relationship."""
- r1.register(r2, True)
- r2.register(r1, True)
+def one(r):
+ r.many = False
+ return r
+
+def many(r):
+ r.many = True
+ return r
+
+def join(r1, r2):
+ r1.register(r2)
+ r2.register(r1)
class SoftwareProject(object):
@@ -135,8 +143,9 @@
def __repr__(self):
return "%s(%r)" % (self.__class__.__name__, self.name)
-
-many2many(SoftwareProject.developers, Developer.projects)
+
+join(many(SoftwareProject.developers),
+ many(Developer.projects))
if __name__ == "__main__":
zope3 = SoftwareProject("Zope3")
More information about the Zodb-checkins
mailing list