rset.py
branchstable
changeset 3625 f03b55a18c43
parent 3551 5a73db781dac
child 3629 559cad62c786
child 3689 deb13e88e037
--- a/rset.py	Fri Oct 09 10:49:21 2009 +0200
+++ b/rset.py	Fri Oct 09 15:10:17 2009 +0200
@@ -399,14 +399,19 @@
             if rqlst.TYPE == 'select':
                 # UNION query, find the subquery from which this entity has been
                 # found
-                rqlst, col = rqlst.locate_subquery(col, etype, self.args)
+                select, col = rqlst.locate_subquery(col, etype, self.args)
+            else:
+                select = rqlst
             # take care, due to outer join support, we may find None
             # values for non final relation
-            for i, attr, x in attr_desc_iterator(rqlst, col):
+            for i, attr, x in attr_desc_iterator(select, col):
+                outerselidx = rqlst.subquery_selection_index(select, i)
+                if outerselidx is None:
+                    continue
                 if x == 'subject':
                     rschema = eschema.subject_relation(attr)
                     if rschema.is_final():
-                        entity[attr] = rowvalues[i]
+                        entity[attr] = rowvalues[outerselidx]
                         continue
                     tetype = rschema.objects(etype)[0]
                     card = rschema.rproperty(etype, tetype, 'cardinality')[0]
@@ -416,7 +421,7 @@
                     card = rschema.rproperty(tetype, etype, 'cardinality')[1]
                 # only keep value if it can't be multivalued
                 if card in '1?':
-                    if rowvalues[i] is None:
+                    if rowvalues[outerselidx] is None:
                         if x == 'subject':
                             rql = 'Any Y WHERE X %s Y, X eid %s'
                         else:
@@ -424,7 +429,7 @@
                         rrset = ResultSet([], rql % (attr, entity.eid))
                         req.decorate_rset(rrset)
                     else:
-                        rrset = self._build_entity(row, i).as_rset()
+                        rrset = self._build_entity(row, outerselidx).as_rset()
                     entity.set_related_cache(attr, x, rrset)
         return entity
 
@@ -550,7 +555,6 @@
             break
         else:
             continue
-        #varname = var.name
         for ref in var.references():
             rel = ref.relation()
             if rel is None or rel.is_types_restriction():