[rql2sql] fix for some queries where eid variable used and entities picked as variable's table
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 10 Jun 2011 16:54:20 +0200
changeset 7493 3c46b9390871
parent 7492 d7d9ad95c329
child 7496 0c75ed374b06
[rql2sql] fix for some queries where eid variable used and entities picked as variable's table
server/sources/rql2sql.py
--- a/server/sources/rql2sql.py	Fri Jun 10 15:35:59 2011 +0200
+++ b/server/sources/rql2sql.py	Fri Jun 10 16:54:20 2011 +0200
@@ -1582,8 +1582,14 @@
             scope = self._state.scopes[var.scope]
             self._state.add_table(sql.split('.', 1)[0], scope=scope)
         except KeyError:
-            sql = '%s.%s%s' % (self._var_table(var), SQL_PREFIX, rtype)
-            #self._state.done.add(var.name)
+            # rtype may be an attribute relation when called from
+            # _visit_var_attr_relation.  take care about 'eid' rtype, since in
+            # some case we may use the `entities` table, so in that case we've
+            # to properly use variable'sql
+            if rtype == 'eid':
+                sql = var.accept(self)
+            else:
+                sql = '%s.%s%s' % (self._var_table(var), SQL_PREFIX, rtype)
         return sql
 
     def _linked_var_sql(self, variable):