From: Federico Caselli Date: Tue, 8 Aug 2023 19:41:29 +0000 (+0200) Subject: Add where criteria example to selected_columns attribute X-Git-Tag: rel_2_0_20~15^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c775f2a3e1078f5b6d5815521c9a9e2440c1fe2;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add where criteria example to selected_columns attribute Change-Id: Ic9050dd846d5a3103aabe6c4d90e5bf2d7b8372d --- diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 060b03b503..b13c53249e 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -6200,6 +6200,18 @@ class Select( :class:`_expression.ColumnElement` objects that are in the :attr:`_expression.FromClause.c` collection of the from element. + A use case for the :attr:`_sql.Select.selected_columns` collection is + to allow the existing columns to be referenced when adding additional + criteria, e.g.:: + + def filter_on_id(my_select, id): + return my_select.where(my_select.selected_columns['id'] == id) + + stmt = select(MyModel) + + # adds "WHERE id=:param" to the statement + stmt = filter_on_id(stmt, 42) + .. note:: The :attr:`_sql.Select.selected_columns` collection does not