schema.py
branchstable
changeset 2222 81130047390d
parent 2201 ddc1f58c8e8b
child 2234 1fbcf202882d
child 2252 dd9758cb77e1
--- 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