hooks/metadata.py
changeset 4812 2eb6a9b33aa5
parent 4811 6c3d5f2a4e01
child 4813 5a55c223612e
--- a/hooks/metadata.py	Thu Mar 04 18:06:03 2010 +0100
+++ b/hooks/metadata.py	Fri Mar 05 12:18:22 2010 +0100
@@ -14,9 +14,8 @@
 from cubicweb.server import hook
 
 
-def eschema_type_eid(session, etype):
+def eschema_eid(session, eschema):
     """get eid of the CWEType entity for the given yams type"""
-    eschema = session.repo.schema.eschema(etype)
     # eschema.eid is None if schema has been readen from the filesystem, not
     # from the database (eg during tests)
     if eschema.eid is None:
@@ -75,7 +74,10 @@
 
 
 class SetIsHook(MetaDataHook):
-    """create a new entity -> set is relation"""
+    """create a new entity -> set is and is_instance_of relations
+
+    those relations are inserted using sql so they are not hookable.
+    """
     __regid__ = 'setis'
     events = ('after_add_entity',)
 
@@ -85,18 +87,14 @@
         session = self._cw
         entity = self.entity
         try:
-            #session.add_relation(entity.eid, 'is',
-            #                     eschema_type_eid(session, entity.__regid__))
             session.system_sql('INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)'
-                           % (entity.eid, eschema_type_eid(session, entity.__regid__)))
+                           % (entity.eid, eschema_eid(session, entity.e_schema)))
         except IndexError:
             # during schema serialization, skip
             return
-        for etype in entity.e_schema.ancestors() + [entity.e_schema]:
-            #session.add_relation(entity.eid, 'is_instance_of',
-            #                     eschema_type_eid(session, etype))
+        for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
             session.system_sql('INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)'
-                               % (entity.eid, eschema_type_eid(session, etype)))
+                               % (entity.eid, eschema_eid(session, eschema)))
 
 
 class SetOwnershipHook(MetaDataHook):