From 00a2f0ef27d573066dfcaac509600876e8d71592 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 19 Sep 2011 16:48:39 -0400 Subject: - added "adapt_on_names" boolean flag to orm.aliased() construct. Allows an aliased() construct to link the ORM entity to a selectable that contains aggregates or other derived forms of a particular attribute, provided the name is the same as that of the entity mapped column. --- lib/sqlalchemy/sql/util.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql/util.py') diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 61a95d764..221a18e51 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -675,18 +675,18 @@ class ClauseAdapter(visitors.ReplacingCloningVisitor): s.c.col1 == table2.c.col1 """ - def __init__(self, selectable, equivalents=None, include=None, exclude=None): + def __init__(self, selectable, equivalents=None, include=None, exclude=None, adapt_on_names=False): self.__traverse_options__ = {'stop_on':[selectable]} self.selectable = selectable self.include = include self.exclude = exclude self.equivalents = util.column_dict(equivalents or {}) + self.adapt_on_names = adapt_on_names def _corresponding_column(self, col, require_embedded, _seen=util.EMPTY_SET): newcol = self.selectable.corresponding_column( col, require_embedded=require_embedded) - if newcol is None and col in self.equivalents and col not in _seen: for equiv in self.equivalents[col]: newcol = self._corresponding_column(equiv, @@ -694,6 +694,8 @@ class ClauseAdapter(visitors.ReplacingCloningVisitor): _seen=_seen.union([col])) if newcol is not None: return newcol + if self.adapt_on_names and newcol is None: + newcol = self.selectable.c.get(col.name) return newcol def replace(self, col): -- cgit v1.2.1