Commit b9d6d32a authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[entity] Add a cw_related_rqlst method returning the RQL select node of cw_related method

This is useful if one wants to modify the query before execution.

A bit a PEP8 style fix in tests along the way.

Related to #12306543.
parent a9dc97b87ced
......@@ -1009,6 +1009,10 @@ class Entity(AppObject):
return rset
def cw_related_rql(self, rtype, role='subject', targettypes=None, limit=None):
return self.cw_related_rqlst(
rtype, role=role, targettypes=targettypes, limit=limit).as_string()
def cw_related_rqlst(self, rtype, role='subject', targettypes=None, limit=None):
vreg = self._cw.vreg
rschema = vreg.schema[rtype]
select = Select()
......@@ -1065,7 +1069,7 @@ class Entity(AppObject):
(mdvar,), VariableRef)
select.add_restriction(rel)
select.add_sort_var(mdvar, asc=False)
return select.as_string()
return select
# generic vocabulary methods ##############################################
......
......@@ -290,17 +290,18 @@ class EntityTC(CubicWebTC):
Personne.fetch_attrs, Personne.cw_fetch_order = fetch_config(('nom', ))
# XXX
self.assertEqual(p.cw_related_rql('evaluee'),
'Any X,AA ORDERBY AA DESC '
'WHERE E eid %(x)s, E evaluee X, X modification_date AA')
'Any X,AA ORDERBY AA DESC '
'WHERE E eid %(x)s, E evaluee X, X modification_date AA')
tag = self.vreg['etypes'].etype_class('Tag')(req)
self.assertEqual(tag.cw_related_rql('tags', 'subject'),
'Any X,AA ORDERBY AA DESC '
'WHERE E eid %(x)s, E tags X, X modification_date AA')
select = tag.cw_related_rqlst('tags', 'subject')
self.assertEqual(select.as_string(),
'Any X,AA ORDERBY AA DESC '
'WHERE E eid %(x)s, E tags X, X modification_date AA')
self.assertEqual(tag.cw_related_rql('tags', 'subject', ('Personne',)),
'Any X,AA,AB ORDERBY AB '
'WHERE E eid %(x)s, E tags X, X is Personne, X modification_date AA, '
'X nom AB')
'Any X,AA,AB ORDERBY AB '
'WHERE E eid %(x)s, E tags X, X is Personne, X modification_date AA, '
'X nom AB')
def test_related_rql_ambiguous_cant_use_fetch_order(self):
with self.admin_access.web_request() as req:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment