Skip to content

Commit

Permalink
set field.referent when db._pending_references (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
laundmo authored Dec 25, 2024
1 parent 3937a08 commit 7abe43d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pydal/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down

0 comments on commit 7abe43d

Please sign in to comment.