mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user