allow to specify targettypes in related_rql stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Sep 2009 12:29:06 +0200
branchstable
changeset 3130 2486163c4630
parent 3129 fab471bee6c1
child 3131 596f893451c0
allow to specify targettypes in related_rql
entity.py
--- a/entity.py	Wed Sep 09 12:28:36 2009 +0200
+++ b/entity.py	Wed Sep 09 12:29:06 2009 +0200
@@ -689,14 +689,16 @@
         self.set_related_cache(rtype, role, rset)
         return self.related(rtype, role, limit, entities)
 
-    def related_rql(self, rtype, role='subject'):
+    def related_rql(self, rtype, role='subject', targettypes=None):
         rschema = self.schema[rtype]
         if role == 'subject':
-            targettypes = rschema.objects(self.e_schema)
+            if targettypes is None:
+                targettypes = rschema.objects(self.e_schema)
             restriction = 'E eid %%(x)s, E %s X' % rtype
             card = greater_card(rschema, (self.e_schema,), targettypes, 0)
         else:
-            targettypes = rschema.subjects(self.e_schema)
+            if targettypes is None:
+                targettypes = rschema.subjects(self.e_schema)
             restriction = 'E eid %%(x)s, X %s E' % rtype
             card = greater_card(rschema, targettypes, (self.e_schema,), 1)
         if len(targettypes) > 1: