(core) Respect sort_by in lookupOne, and allow reverse sorting

Summary:
Ensure that `lookupOne` (via `RecordSet.get_one`) pays attention to the `sort_by` parameter by picking the first of its sorted list of row IDs.

Allow specifying reverse sort order in `sort_by` by adding `"-"` before the column ID.

Suggested in https://grist.slack.com/archives/C0234CPPXPA/p1665756041063079

Test Plan: Extended Python lookup test

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D3675
This commit is contained in:
Alex Hall
2022-10-24 11:09:44 +02:00
parent 0c82b746d0
commit 89259371a5
3 changed files with 47 additions and 6 deletions

View File

@@ -177,7 +177,15 @@ class RecordSet(object):
return False
def get_one(self):
row_id = min(self._row_ids) if self._row_ids else 0
if not self._row_ids:
# Default to the empty/sample record
row_id = 0
elif self._sort_by:
# Pick the first record in the sorted order
row_id = self._row_ids[0]
else:
# Pick the first record in the order of the underlying table, for backwards compatibility.
row_id = min(self._row_ids)
return self._table.Record(row_id, self._source_relation)
def _get_col(self, col_id):