class hybrid_property(interfaces.InspectionAttrInfo):
Known subclasses: sqlalchemy.ext.indexable.index_property
Method | __init__ |
Create a new .hybrid_property . |
Method | comparator |
Provide a modifying decorator that defines a custom comparator producing method. |
Method | deleter |
Provide a modifying decorator that defines a deletion method. |
Method | expression |
Provide a modifying decorator that defines a SQL-expression producing method. |
Method | getter |
Provide a modifying decorator that defines a getter method. |
Method | setter |
Provide a modifying decorator that defines a setter method. |
Method | update_expression |
Provide a modifying decorator that defines an UPDATE tuple producing method. |
Method | __delete__ |
Undocumented |
Method | __get__ |
Undocumented |
Method | __set__ |
Undocumented |
Method | _copy |
Undocumented |
Method | _get_comparator |
Undocumented |
Method | _get_expr |
Undocumented |
Class Variable | is_attribute |
True if this object is a Python :term:`descriptor`. |
Instance Variable | custom_comparator |
Undocumented |
Instance Variable | expr |
Undocumented |
Instance Variable | fdel |
Undocumented |
Instance Variable | fget |
Undocumented |
Instance Variable | fset |
Undocumented |
Instance Variable | update_expr |
Undocumented |
Property | _expr_comparator |
Undocumented |
Property | overrides |
Prefix for a method that is overriding an existing attribute. |
Inherited from InspectionAttrInfo
:
Property | info |
Info dictionary associated with the object, allowing user-defined data to be associated with this .InspectionAttr . |
Inherited from InspectionAttr
(via InspectionAttrInfo
):
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 . |
sqlalchemy.ext.indexable.index_property
Create a new .hybrid_property
.
Usage is typically via decorator:
from sqlalchemy.ext.hybrid import hybrid_property class SomeClass(object): @hybrid_property def value(self): return self._value @value.setter def value(self, value): self._value = value
Provide a modifying decorator that defines a custom comparator producing method.
The return value of the decorated method should be an instance of
~.hybrid.Comparator
.
Note
The .hybrid_property.comparator
decorator
replaces the use of the .hybrid_property.expression
decorator. They cannot be used together.
When a hybrid is invoked at the class level, the
~.hybrid.Comparator
object given here is wrapped inside of a
specialized .QueryableAttribute
, which is the same kind of
object used by the ORM to represent other mapped attributes. The
reason for this is so that other class-level attributes such as
docstrings and a reference to the hybrid itself may be maintained
within the structure that's returned, without any modifications to the
original comparator object passed in.
Note
When referring to a hybrid property from an owning class (e.g.
SomeClass.some_hybrid), an instance of
.QueryableAttribute
is returned, representing the
expression or comparator object as this hybrid object. However,
that object itself has accessors called expression and
comparator; so when attempting to override these decorators on a
subclass, it may be necessary to qualify it using the
.hybrid_property.overrides
modifier first. See that
modifier for details.
Provide a modifying decorator that defines a SQL-expression producing method.
When a hybrid is invoked at the class level, the SQL expression given
here is wrapped inside of a specialized .QueryableAttribute
,
which is the same kind of object used by the ORM to represent other
mapped attributes. The reason for this is so that other class-level
attributes such as docstrings and a reference to the hybrid itself may
be maintained within the structure that's returned, without any
modifications to the original SQL expression passed in.
Note
When referring to a hybrid property from an owning class (e.g.
SomeClass.some_hybrid), an instance of
.QueryableAttribute
is returned, representing the
expression or comparator object as well as this hybrid object.
However, that object itself has accessors called expression and
comparator; so when attempting to override these decorators on a
subclass, it may be necessary to qualify it using the
.hybrid_property.overrides
modifier first. See that
modifier for details.
See Also
Provide a modifying decorator that defines a getter method.
Provide a modifying decorator that defines an UPDATE tuple producing method.
The method accepts a single value, which is the value to be rendered into the SET clause of an UPDATE statement. The method should then process this value into individual column expressions that fit into the ultimate SET clause, and return them as a sequence of 2-tuples. Each tuple contains a column expression as the key and a value to be rendered.
E.g.:
class Person(Base): # ... first_name = Column(String) last_name = Column(String) @hybrid_property def fullname(self): return first_name + " " + last_name @fullname.update_expression def fullname(cls, value): fname, lname = value.split(" ", 1) return [ (cls.first_name, fname), (cls.last_name, lname) ]
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
Prefix for a method that is overriding an existing attribute.
The .hybrid_property.overrides
accessor just returns
this hybrid object, which when called at the class level from
a parent class, will de-reference the "instrumented attribute"
normally returned at this level, and allow modifying decorators
like .hybrid_property.expression
and
.hybrid_property.comparator
to be used without conflicting with the same-named attributes
normally present on the .QueryableAttribute
:
class SuperClass(object): # ... @hybrid_property def foobar(self): return self._foobar class SubClass(SuperClass): # ... @SuperClass.foobar.overrides.expression def foobar(cls): return func.subfoobar(self._foobar)
See Also