class AliasedClass(object):
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 |