diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-09-19 16:48:39 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-09-19 16:48:39 -0400 |
commit | 00a2f0ef27d573066dfcaac509600876e8d71592 (patch) | |
tree | d0fef7a38eff58f36f32c3c54e1d231a68df09db /lib/sqlalchemy/sql/util.py | |
parent | 57ae8672a6be786c32d79faca90666d5b654bce6 (diff) | |
download | sqlalchemy-00a2f0ef27d573066dfcaac509600876e8d71592.tar.gz |
- 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.
Diffstat (limited to 'lib/sqlalchemy/sql/util.py')
-rw-r--r-- | lib/sqlalchemy/sql/util.py | 6 |
1 files changed, 4 insertions, 2 deletions
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): |