entity.py
branchstable
changeset 3955 235a9fda6058
parent 3919 f91bd15f427c
child 3961 d1cbf77db999
--- a/entity.py	Tue Dec 01 12:00:20 2009 +0100
+++ b/entity.py	Tue Dec 01 12:03:42 2009 +0100
@@ -891,15 +891,26 @@
                              kwargs, 'x')
 
     def set_relations(self, _cw_unsafe=False, **kwargs):
+        """add relations to the given object. To set a relation where this entity
+        is the object of the relation, use 'reverse_'<relation> as argument name.
+
+        Values may be an entity, a list of entity, or None (meaning that all
+        relations of the given type from or to this object should be deleted).
+        """
         if _cw_unsafe:
             execute = self.req.unsafe_execute
         else:
             execute = self.req.execute
+        # XXX update cache
         for attr, values in kwargs.iteritems():
             if attr.startswith('reverse_'):
                 restr = 'Y %s X' % attr[len('reverse_'):]
             else:
                 restr = 'X %s Y' % attr
+            if values is None:
+                execute('DELETE %s WHERE X eid %%(x)s' % restr,
+                        {'x': self.eid}, 'x')
+                continue
             if not isinstance(values, (tuple, list, set, frozenset)):
                 values = (values,)
             execute('SET %s WHERE X eid %%(x)s, Y eid IN (%s)' % (