summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-03-29 14:24:39 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-03-29 22:27:41 -0400
commita65d5c250e9fd7090311ef12f28d7d959c6c738e (patch)
tree349f0b4c1127c3d87d9cffb62b5d6e02979a3a9a /lib/sqlalchemy/ext
parent8e857e3f6beecf7510f741428d8d0ba24f5cb71b (diff)
downloadsqlalchemy-a65d5c250e9fd7090311ef12f28d7d959c6c738e.tar.gz
Add a third labeling mode for SELECT statements
Enhanced the disambiguating labels feature of the :func:`~.sql.expression.select` construct such that when a select statement is used in a subquery, repeated column names from different tables are now automatically labeled with a unique label name, without the need to use the full "apply_labels()" feature that conbines tablename plus column name. The disambigated labels are available as plain string keys in the .c collection of the subquery, and most importantly the feature allows an ORM :func:`.orm.aliased` construct against the combination of an entity and an arbitrary subquery to work correctly, targeting the correct columns despite same-named columns in the source tables, without the need for an "apply labels" warning. The existing labeling style is now called LABEL_STYLE_TABLENAME_PLUS_COL. This labeling style will remain used throughout the ORM as has been the case for over a decade, however, the new disambiguation scheme could theoretically replace this scheme entirely. The new scheme would dramatically alter how SQL looks when rendered from the ORM to be more succinct but arguably harder to read. The tablename_columnname scheme used by Join.c is unaffected here, as that's still hardcoded to that scheme. Fixes: #5221 Change-Id: Ib47d9e0f35046b3afc77bef6e65709b93d0c3026
Diffstat (limited to 'lib/sqlalchemy/ext')
-rw-r--r--lib/sqlalchemy/ext/baked.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/sqlalchemy/ext/baked.py b/lib/sqlalchemy/ext/baked.py
index cf67387e4..ff741db32 100644
--- a/lib/sqlalchemy/ext/baked.py
+++ b/lib/sqlalchemy/ext/baked.py
@@ -25,6 +25,7 @@ from ..orm.session import Session
from ..sql import func
from ..sql import literal_column
from ..sql import util as sql_util
+from ..sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL
from ..util import collections_abc
@@ -436,7 +437,7 @@ class Result(object):
self.session, context, self._params, self._post_criteria
)
- context.statement.use_labels = True
+ context.statement._label_style = LABEL_STYLE_TABLENAME_PLUS_COL
if context.autoflush and not context.populate_existing:
self.session._autoflush()
q = context.query.params(self._params).with_session(self.session)