class documentation

class AliasedClass(inspection.Inspectable['AliasedInsp[_O]'], ORMColumnsClauseRole[_O]): (source)

View In Hierarchy

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.expression.Alias` object. A primary purpose of :class:`.AliasedClass` is to serve as an alternate within a SQL statement generated by the ORM, such that an existing mapped entity can be used in multiple contexts. A simple example:: # find all pairs of users with the same name user_alias = aliased(User) session.query(User, user_alias).\ join((user_alias, User.id > user_alias.id)).\ filter(User.name == user_alias.name) :class:`.AliasedClass` is also capable of mapping an existing mapped class to an entirely new selectable, provided this selectable is column- compatible with the existing mapped selectable, and it can also be configured in a mapping as the target of a :func:`_orm.relationship`. See the links below for examples. The :class:`.AliasedClass` object is constructed typically using the :func:`_orm.aliased` function. It also is produced with additional configuration when using the :func:`_orm.with_polymorphic` function. The resulting object is an instance of :class:`.AliasedClass`. This object implements an attribute scheme which produces the same attribute and method interface as the original mapped class, allowing :class:`.AliasedClass` to be compatible with any attribute technique which works on the original class, including hybrid attributes (see :ref:`hybrids_toplevel`). The :class:`.AliasedClass` can be inspected for its underlying :class:`_orm.Mapper`, aliased selectable, and other information using :func:`_sa.inspect`:: from sqlalchemy import inspect my_alias = aliased(MyClass) insp = inspect(my_alias) The resulting inspection object is an instance of :class:`.AliasedInsp`. .. seealso:: :func:`.aliased` :func:`.with_polymorphic` :ref:`relationship_aliased_class` :ref:`relationship_to_window_function`

Method __getattr__ Undocumented
Method __init__ Undocumented
Method __repr__ Undocumented
Method __str__ Undocumented
Instance Variable __name__ Undocumented
Class Method _reconstitute_from_aliased_insp Undocumented
Method _get_from_serialized Undocumented
Instance Variable _aliased_insp Undocumented

Inherited from Inspectable:

Class Variable __slots__ Undocumented

Inherited from ORMColumnsClauseRole (via Inspectable):

Class Variable _role_name Undocumented

Inherited from ColumnsClauseRole (via Inspectable, ORMColumnsClauseRole):

Property _select_iterable Undocumented

Inherited from AllowsLambdaRole (via Inspectable, ORMColumnsClauseRole, ColumnsClauseRole):

Class Variable allows_lambda Undocumented

Inherited from UsesInspection (via Inspectable, ORMColumnsClauseRole, ColumnsClauseRole, AllowsLambdaRole):

Class Variable uses_inspection Undocumented
Class Variable _post_inspect Undocumented
def __getattr__(self, key: str) -> Any: (source)

Undocumented

def __init__(self, mapped_class_or_ac: _EntityType[_O], alias: Optional[FromClause] = None, name: Optional[str] = None, flat: bool = False, adapt_on_names: bool = False, with_polymorphic_mappers: Optional[Sequence[Mapper[Any]]] = None, with_polymorphic_discriminator: Optional[ColumnElement[Any]] = None, base_alias: Optional[AliasedInsp[Any]] = None, use_mapper_path: bool = False, represents_outer_join: bool = False): (source)

Undocumented

def __repr__(self) -> str: (source)

Undocumented

def __str__(self) -> str: (source)

Undocumented

__name__ = (source)

Undocumented

@classmethod
def _reconstitute_from_aliased_insp(cls, aliased_insp: AliasedInsp[_O]) -> AliasedClass[_O]: (source)

Undocumented

def _get_from_serialized(self, key: str, mapped_class: _O, aliased_insp: AliasedInsp[_O]) -> Any: (source)

Undocumented

_aliased_insp = (source)

Undocumented