--- a/.hgtags Wed Jan 14 19:04:20 2009 +0100
+++ b/.hgtags Wed Jan 14 19:04:42 2009 +0100
@@ -8,3 +8,7 @@
5b58fd1aba50680e261857dcc47ede0d1c2ecc59 cubicweb-version-2_99_6
c718f6495ace1e33831862f221e1b93ee0b386e2 cubicweb-debian-version-2_99_6-1
a93da6d88d4ee493ec6bc8852f3ee921af8324ad cubicweb-version_3_0_0
+221886d8e3c84bb31937e24398a783f27cd350dd cubicweb-version-3_0_2
+18d3e56c1de4a6597ab36536964bc66b5550cf98 cubicweb-debian-version-3_0_2-1
+a7366dd3c33cd9ae9c9ec7d49f111367de6deb56 cubicweb-version-3_0_3
+463ba5606b15c4888c60c0933b69295d84e93120 cubicweb-debian-version-3_0_3-1
--- a/common/entity.py Wed Jan 14 19:04:20 2009 +0100
+++ b/common/entity.py Wed Jan 14 19:04:42 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 19:04:20 2009 +0100
+++ b/common/test/data/schema/relations.rel Wed Jan 14 19:04:42 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 19:04:20 2009 +0100
+++ b/common/test/unittest_entity.py Wed Jan 14 19:04:42 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'),