MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / correlate

Method correlate

lib/sqlalchemy/sql/selectable.py:6343–6413  ·  view source on GitHub ↗

r"""Return a new :class:`_expression.Select` which will correlate the given FROM clauses to that of an enclosing :class:`_expression.Select`. Calling this method turns off the :class:`_expression.Select` object's default behavior of "auto-correlation". Normally, FRO

(
        self,
        *fromclauses: Union[Literal[None, False], _FromClauseArgument],
    )

Source from the content-addressed store, hash-verified

6341
6342 @_generative
6343 def correlate(
6344 self,
6345 *fromclauses: Union[Literal[None, False], _FromClauseArgument],
6346 ) -> Self:
6347 r"""Return a new :class:`_expression.Select`
6348 which will correlate the given FROM
6349 clauses to that of an enclosing :class:`_expression.Select`.
6350
6351 Calling this method turns off the :class:`_expression.Select` object's
6352 default behavior of "auto-correlation". Normally, FROM elements
6353 which appear in a :class:`_expression.Select`
6354 that encloses this one via
6355 its :term:`WHERE clause`, ORDER BY, HAVING or
6356 :term:`columns clause` will be omitted from this
6357 :class:`_expression.Select`
6358 object's :term:`FROM clause`.
6359 Setting an explicit correlation collection using the
6360 :meth:`_expression.Select.correlate`
6361 method provides a fixed list of FROM objects
6362 that can potentially take place in this process.
6363
6364 When :meth:`_expression.Select.correlate`
6365 is used to apply specific FROM clauses
6366 for correlation, the FROM elements become candidates for
6367 correlation regardless of how deeply nested this
6368 :class:`_expression.Select`
6369 object is, relative to an enclosing :class:`_expression.Select`
6370 which refers to
6371 the same FROM object. This is in contrast to the behavior of
6372 "auto-correlation" which only correlates to an immediate enclosing
6373 :class:`_expression.Select`.
6374 Multi-level correlation ensures that the link
6375 between enclosed and enclosing :class:`_expression.Select`
6376 is always via
6377 at least one WHERE/ORDER BY/HAVING/columns clause in order for
6378 correlation to take place.
6379
6380 If ``None`` is passed, the :class:`_expression.Select`
6381 object will correlate
6382 none of its FROM entries, and all will render unconditionally
6383 in the local FROM clause.
6384
6385 :param \*fromclauses: one or more :class:`.FromClause` or other
6386 FROM-compatible construct such as an ORM mapped entity to become part
6387 of the correlate collection; alternatively pass a single value
6388 ``None`` to remove all existing correlations.
6389
6390 .. seealso::
6391
6392 :meth:`_expression.Select.correlate_except`
6393
6394 :ref:`tutorial_scalar_subquery`
6395
6396 """
6397
6398 # tests failing when we try to change how these
6399 # arguments are passed
6400

Callers 3

_anonymous_fromclauseMethod · 0.45
correlateMethod · 0.45
correlateMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected