class documentation

class QueryableAttribute(interfaces._MappedAttribute, interfaces.InspectionAttr, interfaces.PropComparator, traversals.HasCopyInternals, roles.JoinTargetRole, roles.OnClauseRole, sql_base.Immutable, sql_base.MemoizedHasCacheKey):

Known subclasses: sqlalchemy.orm.attributes.Mapped

View In Hierarchy

Base class for :term:`descriptor` objects that intercept attribute events on behalf of a .MapperProperty object. The actual .MapperProperty is accessible via the .QueryableAttribute.property attribute.

See Also

.InstrumentedAttribute

.MapperProperty

_orm.Mapper.all_orm_descriptors

_orm.Mapper.attrs

Method __clause​_element__ Undocumented
Method __getattr__ Undocumented
Method __init__ Undocumented
Method __reduce__ Undocumented
Method __str__ Undocumented
Method ​_bulk​_update​_tuples Return setter tuples for a bulk UPDATE.
Method ​_clone Undocumented
Method adapt​_to​_entity Return a copy of this PropComparator which will use the given .AliasedInsp to produce corresponding expressions.
Method and​_ Add additional criteria to the ON clause that's represented by this relationship attribute.
Method get​_history Undocumented
Method hasparent Undocumented
Method label Undocumented
Method of​_type Redefine this object in terms of a polymorphic subclass, _orm.with_polymorphic construct, or _orm.aliased construct.
Method operate Operate on an argument.
Method reverse​_operate Reverse operate on an argument.
Class Variable __visit​_name__ Undocumented
Class Variable ​_cache​_key​_traversal Undocumented
Class Variable is​_attribute True if this object is a Python :term:`descriptor`.
Instance Variable ​_extra​_criteria Undocumented
Instance Variable ​_of​_type Undocumented
Instance Variable ​_parententity Undocumented
Instance Variable class​_ Undocumented
Instance Variable comparator Undocumented
Instance Variable impl Undocumented
Instance Variable key Undocumented
Property ​_annotations Undocumented
Property ​_entity​_namespace Undocumented
Property ​_from​_objects Undocumented
Property ​_impl​_uses​_objects Undocumented
Property ​_supports​_population Undocumented
Property expression The SQL expression object represented by this .QueryableAttribute.
Property info Return the 'info' dictionary for the underlying SQL element.
Property parent Return an inspection instance representing the parent.
Property property Return the .MapperProperty associated with this .QueryableAttribute.

Inherited from _MappedAttribute:

Class Variable __slots__ Undocumented

Inherited from InspectionAttr:

Class Variable __slots__ Undocumented
Class Variable ​_is​_internal​_proxy True if this object is an internal proxy object.
Class Variable is​_aliased​_class True if this object is an instance of .AliasedClass.
Class Variable is​_bundle True if this object is an instance of .Bundle.
Class Variable is​_clause​_element True if this object is an instance of _expression.ClauseElement.
Class Variable is​_instance True if this object is an instance of .InstanceState.
Class Variable is​_mapper True if this object is an instance of _orm.Mapper.
Class Variable is​_property True if this object is an instance of .MapperProperty.
Class Variable is​_selectable Return True if this object is an instance of _expression.Selectable.

Inherited from PropComparator:

Static Method any​_op Undocumented
Static Method has​_op Undocumented
Static Method of​_type​_op Undocumented
Method any Return true if this collection contains any member that meets the given criterion.
Method has Return true if this element references a member which meets the given criterion.
Class Variable __slots__ Undocumented
Instance Variable ​_adapt​_to​_entity Undocumented
Instance Variable prop Undocumented
Property ​_parentmapper legacy; this is renamed to _parententity to be compatible with QueryableAttribute.
Property ​_propagate​_attrs Undocumented
Property adapter Produce a callable that adapts column expressions to suit an aliased version of this comparator.

Inherited from ColumnOperators (via PropComparator):

Method __add__ Implement the + operator.
Method __contains__ Undocumented
Method __div__ Implement the / operator.
Method __eq__ Implement the == operator.
Method __ge__ Implement the >= operator.
Method __getitem__ Implement the [] operator.
Method __gt__ Implement the > operator.
Method __le__ Implement the <= operator.
Method __lshift__ implement the << operator.
Method __lt__ Implement the < operator.
Method __mod__ Implement the % operator.
Method __mul__ Implement the * operator.
Method __ne__ Implement the != operator.
Method __neg__ Implement the - operator.
Method __radd__ Implement the + operator in reverse.
Method __rdiv__ Implement the / operator in reverse.
Method __rmod__ Implement the % operator in reverse.
Method __rmul__ Implement the * operator in reverse.
Method __rshift__ implement the >> operator.
Method __rsub__ Implement the - operator in reverse.
Method __rtruediv__ Implement the // operator in reverse.
Method __sub__ Implement the - operator.
Method __truediv__ Implement the // operator.
Method all​_ Produce an _expression.all_ clause against the parent object.
Method any​_ Produce an _expression.any_ clause against the parent object.
Method asc Produce a _expression.asc clause against the parent object.
Method between Produce a _expression.between clause against the parent object, given the lower and upper range.
Method collate Produce a _expression.collate clause against the parent object, given the collation string.
Method concat Implement the 'concat' operator.
Method contains Implement the 'contains' operator.
Method desc Produce a _expression.desc clause against the parent object.
Method distinct Produce a _expression.distinct clause against the parent object.
Method endswith Implement the 'endswith' operator.
Method ilike Implement the ilike operator, e.g. case insensitive LIKE.
Method in​_ Implement the in operator.
Method is​_ Implement the IS operator.
Method is​_distinct​_from Implement the IS DISTINCT FROM operator.
Method is​_not Implement the IS NOT operator.
Method is​_not​_distinct​_from Implement the IS NOT DISTINCT FROM operator.
Method like Implement the like operator.
Method match Implements a database-specific 'match' operator.
Method not​_ilike implement the NOT ILIKE operator.
Method not​_in implement the NOT IN operator.
Method not​_like implement the NOT LIKE operator.
Method nulls​_first Produce a _expression.nulls_first clause against the parent object.
Method nulls​_last Produce a _expression.nulls_last clause against the parent object.
Method regexp​_match Implements a database-specific 'regexp match' operator.
Method regexp​_replace Implements a database-specific 'regexp replace' operator.
Method startswith Implement the startswith operator.
Class Variable timetuple Hack, allows datetime objects to be compared on the LHS.

Inherited from Operators (via PropComparator, ColumnOperators):

Method __and__ Implement the & operator.
Method __invert__ Implement the ~ operator.
Method __or__ Implement the | operator.
Method bool​_op Return a custom boolean operator.
Method op Produce a generic operator function.

Inherited from HasCopyInternals:

Method ​_copy​_internals Reassign internal elements to be clones of themselves.

Inherited from JoinTargetRole:

Class Variable ​_role​_name Undocumented

Inherited from AllowsLambdaRole (via JoinTargetRole):

Class Variable allows​_lambda Undocumented

Inherited from UsesInspection (via JoinTargetRole):

Class Variable ​_post​_inspect Undocumented
Class Variable uses​_inspection Undocumented

Inherited from SQLRole (via JoinTargetRole, StructuralRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from OnClauseRole:

Class Variable ​_role​_name Undocumented

Inherited from AllowsLambdaRole (via OnClauseRole):

Class Variable allows​_lambda Undocumented

Inherited from SQLRole (via OnClauseRole, StructuralRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from Immutable:

Method ​_copy​_internals Undocumented
Method params Undocumented
Method unique​_params Undocumented
Class Variable ​_is​_immutable Undocumented

Inherited from MemoizedHasCacheKey:

Method ​_generate​_cache​_key return a cache key.

Inherited from HasCacheKey (via MemoizedHasCacheKey):

Class Variable inherit​_cache Indicate if this .HasCacheKey instance should make use of the cache key generation scheme used by its immediate superclass.
Class Method ​_generate​_cache​_attrs generate cache key dispatcher for a new class.
Class Method ​_generate​_cache​_key​_for​_object Undocumented
Method ​_gen​_cache​_key return an optional cache key.
Class Variable __slots__ Undocumented
Class Variable ​_hierarchy​_supports​_caching private attribute which may be set to False to prevent the inherit_cache warning from being emitted for a hierarchy of subclasses.
Class Variable ​_is​_has​_cache​_key Undocumented
def __clause_element__(self):
def __getattr__(self, key):

Undocumented

def __init__(self, class_, key, parententity, impl=None, comparator=None, of_type=None, extra_criteria=()):
def __reduce__(self):

Undocumented

def __str__(self):

Undocumented

def _bulk_update_tuples(self, value):
Return setter tuples for a bulk UPDATE.
def _clone(self, **kw):
def adapt_to_entity(self, adapt_to_entity):
Return a copy of this PropComparator which will use the given .AliasedInsp to produce corresponding expressions.
def and_(self, *other):

Add additional criteria to the ON clause that's represented by this relationship attribute.

E.g.:

stmt = select(User).join(
    User.addresses.and_(Address.email_address != 'foo')
)

stmt = select(User).options(
    joinedload(User.addresses.and_(Address.email_address != 'foo'))
)
New in version 1.4.
def get_history(self, instance, passive=PASSIVE_OFF):

Undocumented

def hasparent(self, state, optimistic=False):

Undocumented

def label(self, name):

Undocumented

def of_type(self, entity):

Redefine this object in terms of a polymorphic subclass, _orm.with_polymorphic construct, or _orm.aliased construct.

Returns a new PropComparator from which further criterion can be evaluated.

e.g.:

query.join(Company.employees.of_type(Engineer)).\
   filter(Engineer.name=='foo')
Parameters
entityUndocumented
class​_a class or mapper indicating that criterion will be against this specific subclass.
def operate(self, op, *other, **kwargs):

Operate on an argument.

This is the lowest level of operation, raises NotImplementedError by default.

Overriding this on a subclass can allow common behavior to be applied to all operations. For example, overriding .ColumnOperators to apply func.lower() to the left and right side:

class MyComparator(ColumnOperators):
    def operate(self, op, other):
        return op(func.lower(self), func.lower(other))
Parameters
opOperator callable.
*otherthe 'other' side of the operation. Will be a single scalar for most operations.
**kwargsmodifiers. These may be passed by special operators such as ColumnOperators.contains.
def reverse_operate(self, op, other, **kwargs):

Reverse operate on an argument.

Usage is the same as operate.

__visit_name__: str =
_cache_key_traversal =

Undocumented

is_attribute: bool =

True if this object is a Python :term:`descriptor`.

This can refer to one of many types. Usually a .QueryableAttribute which handles attributes events on behalf of a .MapperProperty. But can also be an extension type such as .AssociationProxy or .hybrid_property. The .InspectionAttr.extension_type will refer to a constant identifying the specific subtype.

See Also

_orm.Mapper.all_orm_descriptors

_extra_criteria =

Undocumented

_of_type =

Undocumented

_parententity =
class_ =

Undocumented

comparator =

Undocumented

impl =

Undocumented

key =

Undocumented

@property
_annotations =

Undocumented

@property
_entity_namespace =

Undocumented

@property
_from_objects =

Undocumented

@property
_impl_uses_objects =

Undocumented

@util.memoized_property
_supports_population =

Undocumented

@util.memoized_property
expression =

The SQL expression object represented by this .QueryableAttribute.

This will typically be an instance of a _sql.ColumnElement subclass representing a column expression.

Return the 'info' dictionary for the underlying SQL element.

The behavior here is as follows:

  • If the attribute is a column-mapped property, i.e. .ColumnProperty, which is mapped directly to a schema-level _schema.Column object, this attribute will return the .SchemaItem.info dictionary associated with the core-level _schema.Column object.
  • If the attribute is a .ColumnProperty but is mapped to any other kind of SQL expression other than a _schema.Column, the attribute will refer to the .MapperProperty.info dictionary associated directly with the .ColumnProperty, assuming the SQL expression itself does not have its own .info attribute (which should be the case, unless a user-defined SQL construct has defined one).
  • If the attribute refers to any other kind of .MapperProperty, including .RelationshipProperty, the attribute will refer to the .MapperProperty.info dictionary associated with that .MapperProperty.
  • To access the .MapperProperty.info dictionary of the .MapperProperty unconditionally, including for a .ColumnProperty that's associated directly with a _schema.Column, the attribute can be referred to using .QueryableAttribute.property attribute, as MyClass.someattribute.property.info.

See Also

.SchemaItem.info

.MapperProperty.info

Return an inspection instance representing the parent.

This will be either an instance of _orm.Mapper or .AliasedInsp, depending upon the nature of the parent entity which this attribute is associated with.

Return the .MapperProperty associated with this .QueryableAttribute.

Return values here will commonly be instances of .ColumnProperty or .RelationshipProperty.