From 7abe43d725250459f8a4b66e536564473e14ba93 Mon Sep 17 00:00:00 2001 From: laund Date: Wed, 25 Dec 2024 20:32:21 +0100 Subject: [PATCH] set field.referent when db._pending_references (#726) --- pydal/objects.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pydal/objects.py b/pydal/objects.py index 3eed7482d..f0343d84e 100644 --- a/pydal/objects.py +++ b/pydal/objects.py @@ -624,6 +624,28 @@ def _create_references(self): else: self._referenced_by.append(referee) + field_type = referee.type + is_list = field_type[:15] == "list:reference " + if is_list: + ref = field_type[15:].strip() + else: + ref = field_type[10:].strip() + + if "." in ref: + _, throw_it, myfieldname = ref.partition(".") + if not hasattr(self, "_primarykey"): + raise SyntaxError( + "keyed tables can only reference other keyed tables (for now)" + ) + if myfieldname not in self.fields: + raise SyntaxError( + "invalid field '%s' for referenced table '%s'" + " in table '%s'" % (myfieldname, self.name, referee.table.name) + ) + referee.referent = self[myfieldname] + else: + referee.referent = self._id + def _filter_fields(self, record, allow_id=False, writable_only=False): return dict( [