return a class property which produces a legacy :class:`_query.Query` object against the class and the current :class:`.Session` when called. .. legacy:: The :meth:`_orm.scoped_session.query_property` accessor is specific to the legacy :class:`.Query` object and i
(
self, query_cls: Optional[Type[Query[_T]]] = None
)
| 269 | self.registry.clear() |
| 270 | |
| 271 | def query_property( |
| 272 | self, query_cls: Optional[Type[Query[_T]]] = None |
| 273 | ) -> QueryPropertyDescriptor: |
| 274 | """return a class property which produces a legacy |
| 275 | :class:`_query.Query` object against the class and the current |
| 276 | :class:`.Session` when called. |
| 277 | |
| 278 | .. legacy:: The :meth:`_orm.scoped_session.query_property` accessor |
| 279 | is specific to the legacy :class:`.Query` object and is not |
| 280 | considered to be part of :term:`2.0-style` ORM use. |
| 281 | |
| 282 | e.g.:: |
| 283 | |
| 284 | from sqlalchemy.orm import QueryPropertyDescriptor |
| 285 | from sqlalchemy.orm import scoped_session |
| 286 | from sqlalchemy.orm import sessionmaker |
| 287 | |
| 288 | Session = scoped_session(sessionmaker()) |
| 289 | |
| 290 | |
| 291 | class MyClass: |
| 292 | query: QueryPropertyDescriptor = Session.query_property() |
| 293 | |
| 294 | |
| 295 | # after mappers are defined |
| 296 | result = MyClass.query.filter(MyClass.name == "foo").all() |
| 297 | |
| 298 | Produces instances of the session's configured query class by |
| 299 | default. To override and use a custom implementation, provide |
| 300 | a ``query_cls`` callable. The callable will be invoked with |
| 301 | the class's mapper as a positional argument and a session |
| 302 | keyword argument. |
| 303 | |
| 304 | There is no limit to the number of query properties placed on |
| 305 | a class. |
| 306 | |
| 307 | """ |
| 308 | |
| 309 | class query: |
| 310 | def __get__(s, instance: Any, owner: Type[_O]) -> Query[_O]: |
| 311 | if query_cls: |
| 312 | # custom query class |
| 313 | return query_cls(owner, session=self.registry()) # type: ignore # noqa: E501 |
| 314 | else: |
| 315 | # session's configured query class |
| 316 | return self.registry().query(owner) |
| 317 | |
| 318 | return query() |
| 319 | |
| 320 | # START PROXY METHODS scoped_session |
| 321 |
no test coverage detected