diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-07-07 11:12:31 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-07-11 14:20:10 -0400 |
commit | aceefb508ccd0911f52ff0e50324b3fefeaa3f16 (patch) | |
tree | e57124d3ea8b0e2cd7fe1d3ad22170fa956bcafb /lib/sqlalchemy/orm/mapper.py | |
parent | 5c16367ee78fa1a41d6b715152dcc58f45323d2e (diff) | |
download | sqlalchemy-aceefb508ccd0911f52ff0e50324b3fefeaa3f16.tar.gz |
Allow duplicate columns in from clauses and selectables
The :func:`.select` construct and related constructs now allow for
duplication of column labels and columns themselves in the columns clause,
mirroring exactly how column expressions were passed in. This allows
the tuples returned by an executed result to match what was SELECTed
for in the first place, which is how the ORM :class:`.Query` works, so
this establishes better cross-compatibility between the two constructs.
Additionally, it allows column-positioning-sensitive structures such as
UNIONs (i.e. :class:`.CompoundSelect`) to be more intuitively constructed
in those cases where a particular column might appear in more than one
place. To support this change, the :class:`.ColumnCollection` has been
revised to support duplicate columns as well as to allow integer index
access.
Fixes: #4753
Change-Id: Ie09a8116f05c367995c1e43623c51e07971d3bf0
Diffstat (limited to 'lib/sqlalchemy/orm/mapper.py')
-rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 33a474576..5e8d25647 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -45,6 +45,7 @@ from .. import log from .. import schema from .. import sql from .. import util +from ..sql import base as sql_base from ..sql import coercions from ..sql import expression from ..sql import operators @@ -1455,7 +1456,11 @@ class Mapper(InspectionAttr): def _configure_properties(self): # Column and other ClauseElement objects which are mapped - self.columns = self.c = util.OrderedProperties() + + # TODO: technically this should be a DedupeColumnCollection + # however DCC needs changes and more tests to fully cover + # storing columns under a separate key name + self.columns = self.c = sql_base.ColumnCollection() # object attribute names mapped to MapperProperty objects self._props = util.OrderedDict() @@ -1781,7 +1786,7 @@ class Mapper(InspectionAttr): or prop.columns[0] is self.polymorphic_on ) - self.columns[key] = col + self.columns.add(col, key) for col in prop.columns + prop._orig_columns: for col in col.proxy_set: self._columntoproperty[col] = prop |