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): |