From 2de72c7ca9f0b3db5a2265e5a8858c01a91e4ad5 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Fri, 18 Oct 2024 21:58:11 +0100 Subject: [PATCH] fix prefetch when a `ForeignKey` has `db_column_name` set --- piccolo/table.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/piccolo/table.py b/piccolo/table.py index bae9b8a4..1543912d 100644 --- a/piccolo/table.py +++ b/piccolo/table.py @@ -157,7 +157,11 @@ def get_column_by_name(self, name: str) -> Column: """ components = name.split(".") column_name = components[0] - column = [i for i in self.columns if i._meta.name == column_name] + column = [ + i + for i in self.columns + if column_name in (i._meta.name, i._meta.db_column_name) + ] if len(column) != 1: raise ValueError(f"No matching column found with name == {name}") column_object = column[0]