hooks/syncschema.py
changeset 6173 eb386e473044
parent 6142 8bc6eac1fac1
parent 6163 407f54345687
child 6225 a176e68b7d0d
--- a/hooks/syncschema.py	Thu Aug 26 11:45:57 2010 +0200
+++ b/hooks/syncschema.py	Mon Sep 06 15:03:11 2010 +0200
@@ -519,10 +519,16 @@
             insert_rdef_on_subclasses(session, eschema, rschema, rdefdef,
                                       {'composite': entity.composite})
         else:
+            if rschema.symmetric:
+                # for symmetric relations, rdefs will store relation definitions
+                # in both ways (i.e. (subj -> obj) and (obj -> subj))
+                relation_already_defined = len(rschema.rdefs) > 2
+            else:
+                relation_already_defined = len(rschema.rdefs) > 1
             # need to create the relation if no relation definition in the
             # schema and if it has not been added during other event of the same
             # transaction
-            if not (len(rschema.rdefs) > 1 or
+            if not (relation_already_defined or
                     rtype in session.transaction_data.get('createdtables', ())):
                 rschema = schema.rschema(rtype)
                 # create the necessary table