457 elif len(self) == 0: |
457 elif len(self) == 0: |
458 raise NoResultError("No row was found for one()") |
458 raise NoResultError("No row was found for one()") |
459 else: |
459 else: |
460 raise MultipleResultsError("Multiple rows were found for one()") |
460 raise MultipleResultsError("Multiple rows were found for one()") |
461 |
461 |
|
462 def _make_entity(self, row, col): |
|
463 """Instantiate an entity, and store it in the entity cache""" |
|
464 # build entity instance |
|
465 etype = self.description[row][col] |
|
466 entity = self.req.vreg['etypes'].etype_class(etype)(self.req, rset=self, |
|
467 row=row, col=col) |
|
468 entity.eid = self.rows[row][col] |
|
469 # cache entity |
|
470 self.req.set_entity_cache(entity) |
|
471 return entity |
|
472 |
462 def _build_entity(self, row, col): |
473 def _build_entity(self, row, col): |
463 """internal method to get a single entity, returns a partially |
474 """internal method to get a single entity, returns a partially |
464 initialized Entity instance. |
475 initialized Entity instance. |
465 |
476 |
466 partially means that only attributes selected in the RQL query will be |
477 partially means that only attributes selected in the RQL query will be |
486 except KeyError: |
497 except KeyError: |
487 pass |
498 pass |
488 else: |
499 else: |
489 if entity.cw_rset is None: |
500 if entity.cw_rset is None: |
490 # entity has no rset set, this means entity has been created by |
501 # entity has no rset set, this means entity has been created by |
491 # the querier (req is a repository session) and so jas no rset |
502 # the querier (req is a repository session) and so has no rset |
492 # info. Add it. |
503 # info. Add it. |
493 entity.cw_rset = self |
504 entity.cw_rset = self |
494 entity.cw_row = row |
505 entity.cw_row = row |
495 entity.cw_col = col |
506 entity.cw_col = col |
496 return entity |
507 return entity |
497 # build entity instance |
508 entity = self._make_entity(row, col) |
498 etype = self.description[row][col] |
|
499 entity = self.req.vreg['etypes'].etype_class(etype)(req, rset=self, |
|
500 row=row, col=col) |
|
501 entity.eid = eid |
|
502 # cache entity |
|
503 req.set_entity_cache(entity) |
|
504 # try to complete the entity if there are some additional columns |
509 # try to complete the entity if there are some additional columns |
505 if len(rowvalues) > 1: |
510 if len(rowvalues) > 1: |
506 eschema = entity.e_schema |
511 eschema = entity.e_schema |
507 eid_col, attr_cols, rel_cols = self._rset_structure(eschema, col) |
512 eid_col, attr_cols, rel_cols = self._rset_structure(eschema, col) |
508 entity.eid = rowvalues[eid_col] |
513 entity.eid = rowvalues[eid_col] |