Return a :class:`_query.Query` that will use the given :class:`.Session`. While the :class:`_query.Query` object is normally instantiated using the :meth:`.Session.query` method, it is legal to build the :class:`_query.Query` directly without necessar
(self, session: Session)
| 1358 | |
| 1359 | @_generative |
| 1360 | def with_session(self, session: Session) -> Self: |
| 1361 | """Return a :class:`_query.Query` that will use the given |
| 1362 | :class:`.Session`. |
| 1363 | |
| 1364 | While the :class:`_query.Query` |
| 1365 | object is normally instantiated using the |
| 1366 | :meth:`.Session.query` method, it is legal to build the |
| 1367 | :class:`_query.Query` |
| 1368 | directly without necessarily using a :class:`.Session`. Such a |
| 1369 | :class:`_query.Query` object, or any :class:`_query.Query` |
| 1370 | already associated |
| 1371 | with a different :class:`.Session`, can produce a new |
| 1372 | :class:`_query.Query` |
| 1373 | object associated with a target session using this method:: |
| 1374 | |
| 1375 | from sqlalchemy.orm import Query |
| 1376 | |
| 1377 | query = Query([MyClass]).filter(MyClass.id == 5) |
| 1378 | |
| 1379 | result = query.with_session(my_session).one() |
| 1380 | |
| 1381 | """ |
| 1382 | |
| 1383 | self.session = session |
| 1384 | return self |
| 1385 | |
| 1386 | def _legacy_from_self( |
| 1387 | self, *entities: _ColumnsClauseArgument[Any] |
no outgoing calls