[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 07 Jun 2011 10:07:58 +0200
branchstable
changeset 7467 5a6b3e51807d
parent 7465 bb0c89d1a078
child 7468 c202aaf71489
[schema] fix computing of has_text relation: when a fulltext_container relation is added, we need to recompute has_text for the target entity type as well. Also, avoid computation when not needed
schema.py
--- a/schema.py	Tue Jun 07 08:02:11 2011 +0200
+++ b/schema.py	Tue Jun 07 10:07:58 2011 +0200
@@ -378,11 +378,27 @@
     def add_subject_relation(self, rschema):
         """register the relation schema as possible subject relation"""
         super(CubicWebEntitySchema, self).add_subject_relation(rschema)
-        self._update_has_text()
+        if rschema.final:
+            if self.rdef(rschema).get('fulltextindexed'):
+                self._update_has_text()
+        elif rschema.fulltext_container:
+            self._update_has_text()
+
+    def add_object_relation(self, rschema):
+        """register the relation schema as possible object relation"""
+        super(CubicWebEntitySchema, self).add_object_relation(rschema)
+        if rschema.fulltext_container:
+            self._update_has_text()
 
     def del_subject_relation(self, rtype):
         super(CubicWebEntitySchema, self).del_subject_relation(rtype)
-        self._update_has_text(True)
+        if 'has_text' in self.subjrels:
+            self._update_has_text(deletion=True)
+
+    def del_object_relation(self, rtype):
+        super(CubicWebEntitySchema, self).del_object_relation(rtype)
+        if 'has_text' in self.subjrels:
+            self._update_has_text(deletion=True)
 
     def _update_has_text(self, deletion=False):
         may_need_has_text, has_has_text = False, False