rset.py
branchstable
changeset 3625 f03b55a18c43
parent 3551 5a73db781dac
child 3629 559cad62c786
child 3689 deb13e88e037
equal deleted inserted replaced
3624:05932c6f7db2 3625:f03b55a18c43
   397         if len(rowvalues) > 1:
   397         if len(rowvalues) > 1:
   398             rqlst = self.syntax_tree()
   398             rqlst = self.syntax_tree()
   399             if rqlst.TYPE == 'select':
   399             if rqlst.TYPE == 'select':
   400                 # UNION query, find the subquery from which this entity has been
   400                 # UNION query, find the subquery from which this entity has been
   401                 # found
   401                 # found
   402                 rqlst, col = rqlst.locate_subquery(col, etype, self.args)
   402                 select, col = rqlst.locate_subquery(col, etype, self.args)
       
   403             else:
       
   404                 select = rqlst
   403             # take care, due to outer join support, we may find None
   405             # take care, due to outer join support, we may find None
   404             # values for non final relation
   406             # values for non final relation
   405             for i, attr, x in attr_desc_iterator(rqlst, col):
   407             for i, attr, x in attr_desc_iterator(select, col):
       
   408                 outerselidx = rqlst.subquery_selection_index(select, i)
       
   409                 if outerselidx is None:
       
   410                     continue
   406                 if x == 'subject':
   411                 if x == 'subject':
   407                     rschema = eschema.subject_relation(attr)
   412                     rschema = eschema.subject_relation(attr)
   408                     if rschema.is_final():
   413                     if rschema.is_final():
   409                         entity[attr] = rowvalues[i]
   414                         entity[attr] = rowvalues[outerselidx]
   410                         continue
   415                         continue
   411                     tetype = rschema.objects(etype)[0]
   416                     tetype = rschema.objects(etype)[0]
   412                     card = rschema.rproperty(etype, tetype, 'cardinality')[0]
   417                     card = rschema.rproperty(etype, tetype, 'cardinality')[0]
   413                 else:
   418                 else:
   414                     rschema = eschema.object_relation(attr)
   419                     rschema = eschema.object_relation(attr)
   415                     tetype = rschema.subjects(etype)[0]
   420                     tetype = rschema.subjects(etype)[0]
   416                     card = rschema.rproperty(tetype, etype, 'cardinality')[1]
   421                     card = rschema.rproperty(tetype, etype, 'cardinality')[1]
   417                 # only keep value if it can't be multivalued
   422                 # only keep value if it can't be multivalued
   418                 if card in '1?':
   423                 if card in '1?':
   419                     if rowvalues[i] is None:
   424                     if rowvalues[outerselidx] is None:
   420                         if x == 'subject':
   425                         if x == 'subject':
   421                             rql = 'Any Y WHERE X %s Y, X eid %s'
   426                             rql = 'Any Y WHERE X %s Y, X eid %s'
   422                         else:
   427                         else:
   423                             rql = 'Any Y WHERE Y %s X, X eid %s'
   428                             rql = 'Any Y WHERE Y %s X, X eid %s'
   424                         rrset = ResultSet([], rql % (attr, entity.eid))
   429                         rrset = ResultSet([], rql % (attr, entity.eid))
   425                         req.decorate_rset(rrset)
   430                         req.decorate_rset(rrset)
   426                     else:
   431                     else:
   427                         rrset = self._build_entity(row, i).as_rset()
   432                         rrset = self._build_entity(row, outerselidx).as_rset()
   428                     entity.set_related_cache(attr, x, rrset)
   433                     entity.set_related_cache(attr, x, rrset)
   429         return entity
   434         return entity
   430 
   435 
   431     @cached
   436     @cached
   432     def syntax_tree(self):
   437     def syntax_tree(self):
   548         for vref in term.iget_nodes(nodes.VariableRef):
   553         for vref in term.iget_nodes(nodes.VariableRef):
   549             var = vref.variable
   554             var = vref.variable
   550             break
   555             break
   551         else:
   556         else:
   552             continue
   557             continue
   553         #varname = var.name
       
   554         for ref in var.references():
   558         for ref in var.references():
   555             rel = ref.relation()
   559             rel = ref.relation()
   556             if rel is None or rel.is_types_restriction():
   560             if rel is None or rel.is_types_restriction():
   557                 continue
   561                 continue
   558             lhs, rhs = rel.get_variable_parts()
   562             lhs, rhs = rel.get_variable_parts()