[sql generation] fix table scope pb: when an inlined relation is used as principal for the rhs variable, we should adjust lhs variable'scope
--- a/server/rqlannotation.py Mon Mar 07 10:41:04 2011 +0100
+++ b/server/rqlannotation.py Mon Mar 07 17:15:06 2011 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
@@ -135,7 +135,12 @@
# priority should be given to relation which are not in inner queries
# (eg exists)
try:
- stinfo['principal'] = _select_principal(var.scope, joins)
+ stinfo['principal'] = principal = _select_principal(var.scope, joins)
+ if getrschema(principal.r_type).inlined:
+ # the scope of the lhs variable must be equal or outer to the
+ # rhs variable's scope (since it's retrieved from lhs's table)
+ sstinfo = principal.children[0].variable.stinfo
+ sstinfo['scope'] = common_parent(sstinfo['scope'], stinfo['scope']).scope
except CantSelectPrincipal:
stinfo['invariant'] = False
rqlst.need_distinct = need_distinct