[schema] fix Entity.add_relation(RichString(...)...) stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 01 Jul 2009 19:46:47 +0200
branchstable
changeset 2222 81130047390d
parent 2221 d9b85a7b0bdd
child 2223 59588e2d5cd1
[schema] fix Entity.add_relation(RichString(...)...)
schema.py
--- a/schema.py	Wed Jul 01 16:44:37 2009 +0200
+++ b/schema.py	Wed Jul 01 19:46:47 2009 +0200
@@ -109,6 +109,16 @@
         yams_add_relation(relations, format_attrdef, name+'_format', insertidx)
     yams_add_relation(relations, rdef, name, insertidx)
 
+
+yams_EntityType_add_relation = ybo.EntityType.add_relation
+@monkeypatch(ybo.EntityType)
+def add_relation(self, rdef, name=None):
+    yams_EntityType_add_relation(self, rdef, name)
+    if isinstance(rdef, RichString) and not rdef in self._defined:
+        format_attr_name = (name or rdef.name) + '_format'
+        rdef = self.get_relations(format_attr_name).next()
+        self._ensure_relation_type(rdef)
+
 def display_name(req, key, form=''):
     """return a internationalized string for the key (schema entity or relation
     name) in a given form