class documentation

class AliasedClass(object):

View In Hierarchy

Represents an "aliased" form of a mapped class for usage with Query.

The ORM equivalent of a ~sqlalchemy.sql.expression.alias construct, this object mimics the mapped class using a __getattr__ scheme and maintains a reference to a real ~sqlalchemy.sql.expression.Alias object.

A primary purpose of .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)

.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 _orm.relationship. See the links below for examples.

The .AliasedClass object is constructed typically using the _orm.aliased function. It also is produced with additional configuration when using the _orm.with_polymorphic function.

The resulting object is an instance of .AliasedClass. This object implements an attribute scheme which produces the same attribute and method interface as the original mapped class, allowing .AliasedClass to be compatible with any attribute technique which works on the original class, including hybrid attributes (see :ref:`hybrids_toplevel`).

The .AliasedClass can be inspected for its underlying _orm.Mapper, aliased selectable, and other information using _sa.inspect:

from sqlalchemy import inspect
my_alias = aliased(MyClass)
insp = inspect(my_alias)

The resulting inspection object is an instance of .AliasedInsp.

Class Method ​_reconstitute​_from​_aliased​_insp Undocumented
Method __getattr__ Undocumented
Method __init__ Undocumented
Method __repr__ Undocumented
Method __str__ Undocumented
Method ​_get​_from​_serialized Undocumented
Instance Variable __name__ Undocumented
Instance Variable ​_aliased​_insp Undocumented
@classmethod
def _reconstitute_from_aliased_insp(cls, aliased_insp):

Undocumented

def __getattr__(self, key):

Undocumented

def __init__(self, mapped_class_or_ac, alias=None, name=None, flat=False, adapt_on_names=False, with_polymorphic_mappers=(), with_polymorphic_discriminator=None, base_alias=None, use_mapper_path=False, represents_outer_join=False):

Undocumented

def __repr__(self):

Undocumented

def __str__(self):

Undocumented

def _get_from_serialized(self, key, mapped_class, aliased_insp):

Undocumented

__name__ =

Undocumented

_aliased_insp =

Undocumented