[repo] take care of inlined relation in session.[add|delete]_relation stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 14 Sep 2009 11:08:57 +0200
branchstable
changeset 3197 b27d19c0db1c
parent 3196 77936fa67ae6
child 3198 d2f48d30e73e
child 3211 7918d4a5cdbf
[repo] take care of inlined relation in session.[add|delete]_relation
server/session.py
--- a/server/session.py	Mon Sep 14 10:15:11 2009 +0200
+++ b/server/session.py	Mon Sep 14 11:08:57 2009 +0200
@@ -84,13 +84,13 @@
         session._threaddata = self.actual_session()._threaddata
         return session
 
-    def _change_relation(self, cb, fromeid, rtype, toeid):
+    def _super_call(self, __cb, *args, **kwargs):
         if self.is_super_session:
-            cb(self, fromeid, rtype, toeid)
+            __cb(self, *args, **kwargs)
             return
         self.is_super_session = True
         try:
-            cb(self, fromeid, rtype, toeid)
+            __cb(self, *args, **kwargs)
         finally:
             self.is_super_session = False
 
@@ -105,8 +105,15 @@
         You may use this in hooks when you know both eids of the relation you
         want to add.
         """
-        self._change_relation(self.repo.glob_add_relation,
-                              fromeid, rtype, toeid)
+        if self.vreg.schema[rtype].inlined:
+            entity = self.entity_from_eid(fromeid)
+            entity[rtype] = toeid
+            self._super_call(self.repo.glob_update_entity,
+                             entity, set((rtype,)))
+        else:
+            self._super_call(self.repo.glob_add_relation,
+                             fromeid, rtype, toeid)
+
     def delete_relation(self, fromeid, rtype, toeid):
         """provide direct access to the repository method to delete a relation.
 
@@ -118,8 +125,14 @@
         You may use this in hooks when you know both eids of the relation you
         want to delete.
         """
-        self._change_relation(self.repo.glob_delete_relation,
-                              fromeid, rtype, toeid)
+        if self.vreg.schema[rtype].inlined:
+            entity = self.entity_from_eid(fromeid)
+            entity[rtype] = None
+            self._super_call(self.repo.glob_update_entity,
+                             entity, set((rtype,)))
+        else:
+            self._super_call(self.repo.glob_delete_relation,
+                             fromeid, rtype, toeid)
 
     # relations cache handling #################################################