fix bug in entity.related_rql(): fetch_attr list / fetchorder weren't computed correctly
--- a/common/entity.py Wed Jan 14 17:16:33 2009 +0100
+++ b/common/entity.py Wed Jan 14 17:55:50 2009 +0100
@@ -756,10 +756,11 @@
restriction = 'E eid %%(x)s, X %s E' % rtype
card = greater_card(rschema, targettypes, (self.e_schema,), 1)
if len(targettypes) > 1:
- fetchattrs = set()
+ fetchattrs_list = []
for ttype in targettypes:
etypecls = self.vreg.etype_class(ttype)
- fetchattrs &= frozenset(etypecls.fetch_attrs)
+ fetchattrs_list.append(set(etypecls.fetch_attrs))
+ fetchattrs = reduce(set.intersection, fetchattrs_list)
rql = etypecls.fetch_rql(self.req.user, [restriction], fetchattrs,
settype=False)
else:
--- a/common/test/data/schema/relations.rel Wed Jan 14 17:16:33 2009 +0100
+++ b/common/test/data/schema/relations.rel Wed Jan 14 17:55:50 2009 +0100
@@ -11,3 +11,6 @@
Tag tags Note
Tag tags Personne
+
+Affaire liee_a Societe
+Affaire liee_a Personne
--- a/common/test/unittest_entity.py Wed Jan 14 17:16:33 2009 +0100
+++ b/common/test/unittest_entity.py Wed Jan 14 17:55:50 2009 +0100
@@ -100,7 +100,7 @@
self.assertEquals(sorted(user._related_cache), ['in_group_subject', 'primary_email_subject'])
for group in groups:
self.failIf('in_group_subject' in group._related_cache, group._related_cache.keys())
-
+
def test_related_limit(self):
p = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien')
for tag in u'abcd':
@@ -164,7 +164,20 @@
Personne.fetch_attrs = pfetch_attrs
Societe.fetch_attrs = sfetch_attrs
-
+ def test_related_rql(self):
+ from cubicweb.entities import fetch_config
+ Personne = self.vreg.etype_class('Personne')
+ Societe = self.vreg.etype_class('Societe')
+ Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', 'prenom', 'sexe'))
+ Societe.fetch_attrs, Societe.fetch_order = fetch_config(('nom', 'web'))
+ aff = self.add_entity('Affaire', sujet=u'my subject', ref=u'the ref')
+ self.assertEquals(aff.related_rql('liee_a'),
+ 'Any X,AA,AB ORDERBY AA ASC WHERE E eid %(x)s, E liee_a X, '
+ 'X nom AA, X modification_date AB')
+ Societe.fetch_attrs = ('web',)
+ self.assertEquals(aff.related_rql('liee_a'),
+ 'Any X ORDERBY Z DESC WHERE X modification_date Z, E eid %(x)s, E liee_a X')
+
def test_entity_unrelated(self):
p = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien')
e = self.add_entity('Tag', name=u'x')
@@ -275,6 +288,7 @@
('travaille', 'subject'),
('ecrit_par', 'object'),
('evaluee', 'object'),
+ ('liee_a', 'object'),
('tags', 'object')])
self.assertListEquals(rbc(e.relations_by_category('generated')),
[('created_by', 'subject'),