Produce an :class:`.AliasedClass` construct which specifies columns for descendant mappers of the given base. Using this method will ensure that each descendant mapper's tables are included in the FROM clause, and will allow filter() criterion to be used against those tables. The r
(
base: Union[Type[_O], Mapper[_O]],
classes: Union[Literal["*"], Iterable[Type[Any]]],
selectable: Union[Literal[False, None], FromClause] = False,
flat: bool = False,
polymorphic_on: Optional[ColumnElement[Any]] = None,
aliased: bool = False,
innerjoin: bool = False,
adapt_on_names: bool = False,
name: Optional[str] = None,
_use_mapper_path: bool = False,
)
| 2521 | |
| 2522 | |
| 2523 | def with_polymorphic( |
| 2524 | base: Union[Type[_O], Mapper[_O]], |
| 2525 | classes: Union[Literal["*"], Iterable[Type[Any]]], |
| 2526 | selectable: Union[Literal[False, None], FromClause] = False, |
| 2527 | flat: bool = False, |
| 2528 | polymorphic_on: Optional[ColumnElement[Any]] = None, |
| 2529 | aliased: bool = False, |
| 2530 | innerjoin: bool = False, |
| 2531 | adapt_on_names: bool = False, |
| 2532 | name: Optional[str] = None, |
| 2533 | _use_mapper_path: bool = False, |
| 2534 | ) -> AliasedClass[_O]: |
| 2535 | """Produce an :class:`.AliasedClass` construct which specifies |
| 2536 | columns for descendant mappers of the given base. |
| 2537 | |
| 2538 | Using this method will ensure that each descendant mapper's |
| 2539 | tables are included in the FROM clause, and will allow filter() |
| 2540 | criterion to be used against those tables. The resulting |
| 2541 | instances will also have those columns already loaded so that |
| 2542 | no "post fetch" of those columns will be required. |
| 2543 | |
| 2544 | .. seealso:: |
| 2545 | |
| 2546 | :ref:`with_polymorphic` - full discussion of |
| 2547 | :func:`_orm.with_polymorphic`. |
| 2548 | |
| 2549 | :param base: Base class to be aliased. |
| 2550 | |
| 2551 | :param classes: a single class or mapper, or list of |
| 2552 | class/mappers, which inherit from the base class. |
| 2553 | Alternatively, it may also be the string ``'*'``, in which case |
| 2554 | all descending mapped classes will be added to the FROM clause. |
| 2555 | |
| 2556 | :param aliased: when True, the selectable will be aliased. For a |
| 2557 | JOIN, this means the JOIN will be SELECTed from inside of a subquery |
| 2558 | unless the :paramref:`_orm.with_polymorphic.flat` flag is set to |
| 2559 | True, which is recommended for simpler use cases. |
| 2560 | |
| 2561 | :param flat: Boolean, will be passed through to the |
| 2562 | :meth:`_expression.FromClause.alias` call so that aliases of |
| 2563 | :class:`_expression.Join` objects will alias the individual tables |
| 2564 | inside the join, rather than creating a subquery. This is generally |
| 2565 | supported by all modern databases with regards to right-nested joins |
| 2566 | and generally produces more efficient queries. Setting this flag is |
| 2567 | recommended as long as the resulting SQL is functional. |
| 2568 | |
| 2569 | :param selectable: a table or subquery that will |
| 2570 | be used in place of the generated FROM clause. This argument is |
| 2571 | required if any of the desired classes use concrete table |
| 2572 | inheritance, since SQLAlchemy currently cannot generate UNIONs |
| 2573 | among tables automatically. If used, the ``selectable`` argument |
| 2574 | must represent the full set of tables and columns mapped by every |
| 2575 | mapped class. Otherwise, the unaccounted mapped columns will |
| 2576 | result in their table being appended directly to the FROM clause |
| 2577 | which will usually lead to incorrect results. |
| 2578 | |
| 2579 | When left at its default value of ``False``, the polymorphic |
| 2580 | selectable assigned to the base mapper is used for selecting rows. |