From e4a47d7e4b04d67b3a062cd7f6d1fb2a0d16ca6a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 8 Aug 2006 16:39:18 +0000 Subject: [PATCH] fix to lazy loads when mapping to joins --- CHANGES | 1 + lib/sqlalchemy/orm/properties.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 5dd60be3a3..16f10e81a8 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,7 @@ for sqlite applications that dispose of threads en masse) - fixed small pickle bug(s) with lazy loaders [ticket:265] [ticket:267] - fixed possible error in mysql reflection where certain versions return an array instead of string for SHOW CREATE TABLE call +- fix to lazy loads when mapping to joins 0.2.6 - big overhaul to schema to allow truly composite primary and foreign diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index f03feaa1c2..26717fb659 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -435,18 +435,20 @@ class LazyLoader(PropertyLoader): def create_lazy_clause(table, primaryjoin, secondaryjoin, foreignkey): binds = {} reverse = {} + def column_in_table(table, column): + return table.corresponding_column(column, raiseerr=False, keys_ok=False) is not None + def bind_label(): return "lazy_" + hex(random.randint(0, 65535))[2:] - def visit_binary(binary): circular = isinstance(binary.left, schema.Column) and isinstance(binary.right, schema.Column) and binary.left.table is binary.right.table - if isinstance(binary.left, schema.Column) and isinstance(binary.right, schema.Column) and ((not circular and binary.left.table is table) or (circular and binary.right in foreignkey)): + if isinstance(binary.left, schema.Column) and isinstance(binary.right, schema.Column) and ((not circular and column_in_table(table, binary.left)) or (circular and binary.right in foreignkey)): col = binary.left binary.left = binds.setdefault(binary.left, sql.BindParamClause(bind_label(), None, shortname=binary.left.name, type=binary.right.type)) reverse[binary.right] = binds[col] - if isinstance(binary.right, schema.Column) and isinstance(binary.left, schema.Column) and ((not circular and binary.right.table is table) or (circular and binary.left in foreignkey)): + if isinstance(binary.right, schema.Column) and isinstance(binary.left, schema.Column) and ((not circular and column_in_table(table, binary.right)) or (circular and binary.left in foreignkey)): col = binary.right binary.right = binds.setdefault(binary.right, sql.BindParamClause(bind_label(), None, shortname=binary.right.name, type=binary.left.type)) -- 2.47.2