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

Method correlate

lib/sqlalchemy/orm/query.py:1169–1204  ·  view source on GitHub ↗

Return a :class:`.Query` construct which will correlate the given FROM clauses to that of an enclosing :class:`.Query` or :func:`~.expression.select`. The method here accepts mapped classes, :func:`.aliased` constructs, and :class:`_orm.Mapper` constructs as argument

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

Source from the content-addressed store, hash-verified

1167
1168 @_generative
1169 def correlate(
1170 self,
1171 *fromclauses: Union[Literal[None, False], _FromClauseArgument],
1172 ) -> Self:
1173 """Return a :class:`.Query` construct which will correlate the given
1174 FROM clauses to that of an enclosing :class:`.Query` or
1175 :func:`~.expression.select`.
1176
1177 The method here accepts mapped classes, :func:`.aliased` constructs,
1178 and :class:`_orm.Mapper` constructs as arguments, which are resolved
1179 into expression constructs, in addition to appropriate expression
1180 constructs.
1181
1182 The correlation arguments are ultimately passed to
1183 :meth:`_expression.Select.correlate`
1184 after coercion to expression constructs.
1185
1186 The correlation arguments take effect in such cases
1187 as when :meth:`_query.Query.from_self` is used, or when
1188 a subquery as returned by :meth:`_query.Query.subquery` is
1189 embedded in another :func:`_expression.select` construct.
1190
1191 .. seealso::
1192
1193 :meth:`_sql.Select.correlate` - v2 equivalent method.
1194
1195 """
1196
1197 self._auto_correlate = False
1198 if fromclauses and fromclauses[0] in {None, False}:
1199 self._correlate = ()
1200 else:
1201 self._correlate = self._correlate + tuple(
1202 coercions.expect(roles.FromClauseRole, f) for f in fromclauses
1203 )
1204 return self
1205
1206 @_generative
1207 def autoflush(self, setting: bool) -> Self:

Calls

no outgoing calls