r"""Represents an "aliased" form of a mapped class for usage with Query. The ORM equivalent of a :func:`~sqlalchemy.sql.expression.alias` construct, this object mimics the mapped class using a ``__getattr__`` scheme and maintains a reference to a real :class:`~sqlalchemy.sql.express
| 633 | |
| 634 | |
| 635 | class AliasedClass( |
| 636 | inspection.Inspectable["AliasedInsp[_O]"], ORMColumnsClauseRole[_O] |
| 637 | ): |
| 638 | r"""Represents an "aliased" form of a mapped class for usage with Query. |
| 639 | |
| 640 | The ORM equivalent of a :func:`~sqlalchemy.sql.expression.alias` |
| 641 | construct, this object mimics the mapped class using a |
| 642 | ``__getattr__`` scheme and maintains a reference to a |
| 643 | real :class:`~sqlalchemy.sql.expression.Alias` object. |
| 644 | |
| 645 | A primary purpose of :class:`.AliasedClass` is to serve as an alternate |
| 646 | within a SQL statement generated by the ORM, such that an existing |
| 647 | mapped entity can be used in multiple contexts. A simple example:: |
| 648 | |
| 649 | # find all pairs of users with the same name |
| 650 | user_alias = aliased(User) |
| 651 | session.query(User, user_alias).join( |
| 652 | (user_alias, User.id > user_alias.id) |
| 653 | ).filter(User.name == user_alias.name) |
| 654 | |
| 655 | :class:`.AliasedClass` is also capable of mapping an existing mapped |
| 656 | class to an entirely new selectable, provided this selectable is column- |
| 657 | compatible with the existing mapped selectable, and it can also be |
| 658 | configured in a mapping as the target of a :func:`_orm.relationship`. |
| 659 | See the links below for examples. |
| 660 | |
| 661 | The :class:`.AliasedClass` object is constructed typically using the |
| 662 | :func:`_orm.aliased` function. It also is produced with additional |
| 663 | configuration when using the :func:`_orm.with_polymorphic` function. |
| 664 | |
| 665 | The resulting object is an instance of :class:`.AliasedClass`. |
| 666 | This object implements an attribute scheme which produces the |
| 667 | same attribute and method interface as the original mapped |
| 668 | class, allowing :class:`.AliasedClass` to be compatible |
| 669 | with any attribute technique which works on the original class, |
| 670 | including hybrid attributes (see :ref:`hybrids_toplevel`). |
| 671 | |
| 672 | The :class:`.AliasedClass` can be inspected for its underlying |
| 673 | :class:`_orm.Mapper`, aliased selectable, and other information |
| 674 | using :func:`_sa.inspect`:: |
| 675 | |
| 676 | from sqlalchemy import inspect |
| 677 | |
| 678 | my_alias = aliased(MyClass) |
| 679 | insp = inspect(my_alias) |
| 680 | |
| 681 | The resulting inspection object is an instance of :class:`.AliasedInsp`. |
| 682 | |
| 683 | |
| 684 | .. seealso:: |
| 685 | |
| 686 | :func:`.aliased` |
| 687 | |
| 688 | :func:`.with_polymorphic` |
| 689 | |
| 690 | :ref:`relationship_aliased_class` |
| 691 | |
| 692 | :ref:`relationship_to_window_function` |
no outgoing calls
no test coverage detected