# HG changeset patch # User Sylvain Thénault # Date 1255594432 -7200 # Node ID 554a588ffaea3889354581d5ad0f4c1ce606f164 # Parent c765adac7f5c551962ddd50a9574a357f7e27046 [entity] make related_rql honors its targettypes argument diff -r c765adac7f5c -r 554a588ffaea entity.py --- a/entity.py Wed Oct 14 17:45:49 2009 +0200 +++ b/entity.py Thu Oct 15 10:13:52 2009 +0200 @@ -691,14 +691,18 @@ def related_rql(self, rtype, role='subject', targettypes=None): rschema = self.schema[rtype] if role == 'subject': + restriction = 'E eid %%(x)s, E %s X' % rtype if targettypes is None: targettypes = rschema.objects(self.e_schema) - restriction = 'E eid %%(x)s, E %s X' % rtype + else: + restriction += 'E is IN (%s)' % ','.join(targettypes) card = greater_card(rschema, (self.e_schema,), targettypes, 0) else: + restriction = 'E eid %%(x)s, X %s E' % rtype if targettypes is None: targettypes = rschema.subjects(self.e_schema) - restriction = 'E eid %%(x)s, X %s E' % rtype + else: + restriction += 'E is IN (%s)' % ','.join(targettypes) card = greater_card(rschema, targettypes, (self.e_schema,), 1) if len(targettypes) > 1: fetchattrs_list = [] diff -r c765adac7f5c -r 554a588ffaea test/unittest_entity.py --- a/test/unittest_entity.py Wed Oct 14 17:45:49 2009 +0200 +++ b/test/unittest_entity.py Thu Oct 15 10:13:52 2009 +0200 @@ -192,7 +192,19 @@ Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', )) # XXX self.assertEquals(p.related_rql('evaluee'), - 'Any X,AA ORDERBY Z DESC WHERE X modification_date Z, E eid %(x)s, E evaluee X, X modification_date AA') + 'Any X,AA ORDERBY Z DESC ' + 'WHERE X modification_date Z, E eid %(x)s, E evaluee X, ' + 'X modification_date AA') + + tag = self.vreg['etypes'].etype_class('Tag')(self.request()) + self.assertEquals(tag.related_rql('tags', 'subject'), + 'Any X,AA ORDERBY Z DESC ' + 'WHERE X modification_date Z, E eid %(x)s, E tags X, ' + 'X modification_date AA') + self.assertEquals(tag.related_rql('tags', 'subject', ('Personne',)), + 'Any X,AA,AB ORDERBY AA ASC ' + 'WHERE E eid %(x)s, E tags XE is IN (Personne), X nom AA, ' + 'X modification_date AB') def test_unrelated_rql_security_1(self): user = self.request().user