__init__.py
branchstable
changeset 3670 b7ec030a5e10
parent 3669 4eb33ee29c84
child 3674 387d51af966d
child 3684 c0a854810942
--- a/__init__.py	Wed Oct 14 15:59:00 2009 +0200
+++ b/__init__.py	Wed Oct 14 16:30:46 2009 +0200
@@ -136,7 +136,14 @@
         relations = []
         restrictions = set()
         cachekey = []
+        pending_relations = []
         for attr, value in kwargs.iteritems():
+            if isinstance(value, (tuple, list, set, frozenset)):
+                if len(value) == 1:
+                    value = iter(value).next()
+                else:
+                    pending_relations.append( (attr, value) )
+                    continue
             if hasattr(value, 'eid'): # non final relation
                 rvar = attr.upper()
                 # XXX safer detection of object relation
@@ -155,7 +162,16 @@
             rql = '%s: %s' % (rql, ', '.join(relations))
         if restrictions:
             rql = '%s WHERE %s' % (rql, ', '.join(restrictions))
-        return self.execute(rql, kwargs, cachekey).get_entity(0, 0)
+        created = self.execute(rql, kwargs, cachekey).get_entity(0, 0)
+        for attr, values in pending_relations:
+            if attr.startswith('reverse_'):
+                restr = 'Y %s X' % attr[len('reverse_'):]
+            else:
+                restr = 'X %s Y' % attr
+            self.execute('SET %s WHERE X eid %%(x)s, Y eid IN (%s)' % (
+                restr, ','.join(str(r.eid) for r in values)),
+                         {'x': created.eid}, 'x')
+        return created
 
     # url generation methods ##################################################