class documentation

class ColumnProperty(StrategizedProperty):

View In Hierarchy

Describes an object attribute that corresponds to a table column.

Public constructor is the _orm.column_property function.

Class ​Comparator Produce boolean, comparison, and other operators for .ColumnProperty attributes.
Method __clause​_element__ Allow the ColumnProperty to work in expression before it is turned into an instrumented attribute.
Method __init__ Provide a column-level property for use with a mapping.
Method __str__ Undocumented
Method ​_getcommitted Undocumented
Method ​_memoized​_attr​_​_deferred​_column​_loader Undocumented
Method ​_memoized​_attr​_​_raise​_column​_loader Undocumented
Method ​_memoized​_attr​_​_renders​_in​_subqueries Undocumented
Method copy Undocumented
Method do​_init Perform subclass-specific initialization post-mapper-creation steps.
Method instrument​_class Hook called by the Mapper to the property to initiate instrumentation of the class attribute managed by this MapperProperty.
Method merge Merge the attribute represented by this MapperProperty from source to destination object.
Class Variable __slots__ Undocumented
Class Variable ​_links​_to​_entity True if this MapperProperty refers to a mapped entity.
Class Variable inherit​_cache Indicate if this .HasCacheKey instance should make use of the cache key generation scheme used by its immediate superclass.
Class Variable strategy​_wildcard​_key Undocumented
Instance Variable ​_orig​_columns Undocumented
Instance Variable active​_history Undocumented
Instance Variable columns Undocumented
Instance Variable comparator​_factory Undocumented
Instance Variable deferred Undocumented
Instance Variable descriptor Undocumented
Instance Variable doc Undocumented
Instance Variable expire​_on​_flush Undocumented
Instance Variable group Undocumented
Instance Variable info Undocumented
Instance Variable instrument Undocumented
Instance Variable raiseload Undocumented
Instance Variable strategy​_key Undocumented
Property expression Return the primary column or expression for this ColumnProperty.

Inherited from StrategizedProperty:

Class Method strategy​_for Undocumented
Class Method ​_strategy​_lookup Undocumented
Method ​_get​_context​_loader Undocumented
Method ​_get​_strategy Undocumented
Method ​_memoized​_attr​_​_default​_path​_loader​_key Undocumented
Method ​_memoized​_attr​_​_wildcard​_token Undocumented
Method create​_row​_processor Produce row processing functions and append to the given set of populators lists.
Method post​_instrument​_class Perform instrumentation adjustments that need to occur after init() has completed.
Method setup Called by Query for the purposes of constructing a SQL statement.
Class Variable ​_all​_strategies Undocumented
Instance Variable ​_strategies Undocumented
Instance Variable strategy Undocumented

Inherited from MapperProperty (via StrategizedProperty):

Method __repr__ Undocumented
Method ​_memoized​_attr​_info Info dictionary associated with the object, allowing user-defined data to be associated with this .InspectionAttr.
Method cascade​_iterator Iterate through instances related to the given instance for a particular 'cascade', starting with this MapperProperty.
Method init Called after all mappers are created to assemble relationships between mappers and perform other post-mapper-creation initialization steps.
Method set​_parent Set the parent mapper that references this MapperProperty.
Class Variable ​_cache​_key​_traversal Undocumented
Class Variable cascade The set of 'cascade' attribute names.
Class Variable is​_property Part of the InspectionAttr interface; states this object is a mapper property.
Instance Variable ​_configure​_finished Undocumented
Instance Variable ​_configure​_started Undocumented
Instance Variable parent Undocumented
Property class​_attribute Return the class-bound descriptor corresponding to this .MapperProperty.

Inherited from HasCacheKey (via StrategizedProperty, MapperProperty):

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.
Method ​_generate​_cache​_key return a cache key.
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

Inherited from InspectionAttr (via StrategizedProperty, MapperProperty):

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​_attribute True if this object is a Python :term:`descriptor`.
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​_selectable Return True if this object is an instance of _expression.Selectable.

Inherited from MemoizedSlots (via StrategizedProperty, MapperProperty):

Method __getattr__ Undocumented
Method ​_fallback​_getattr Undocumented
def __clause_element__(self):
Allow the ColumnProperty to work in expression before it is turned into an instrumented attribute.
def __init__(self, *columns, **kwargs):

Provide a column-level property for use with a mapping.

Column-based properties can normally be applied to the mapper's properties dictionary using the _schema.Column element directly. Use this function when the given column is not directly present within the mapper's selectable; examples include SQL expressions, functions, and scalar SELECT queries.

The _orm.column_property function returns an instance of .ColumnProperty.

Columns that aren't present in the mapper's selectable won't be persisted by the mapper and are effectively "read-only" attributes.

See Also

:ref:`column_property_options` - to map columns while including mapping options

:ref:`mapper_column_property_sql_expressions` - to map SQL expressions

Parameters
*columnsUndocumented
**kwargsUndocumented
colslist of Column objects to be mapped.
active_history=​FalseWhen True, indicates that the "previous" value for a scalar attribute should be loaded when replaced, if not already loaded. Normally, history tracking logic for simple non-primary-key scalar values only needs to be aware of the "new" value in order to perform a flush. This flag is available for applications that make use of .attributes.get_history or .Session.is_modified which also need to know the "previous" value of the attribute.
comparator​_factorya class which extends .ColumnProperty.Comparator which provides custom SQL clause generation for comparison operations.
groupa group name for this property when marked as deferred.
deferredwhen True, the column property is "deferred", meaning that it does not load immediately, and is instead loaded when the attribute is first accessed on an instance. See also ~sqlalchemy.orm.deferred.
docoptional string that will be applied as the doc on the class-bound descriptor.
expire_on_flush=​TrueDisable expiry on flush. A column_property() which refers to a SQL expression (and not a single table-bound column) is considered to be a "read only" property; populating it has no effect on the state of data, and it can only return database state. For this reason a column_property()'s value is expired whenever the parent object is involved in a flush, that is, has any kind of "dirty" state within a flush. Setting this parameter to False will have the effect of leaving any existing value present after the flush proceeds. Note however that the .Session with default expiration settings still expires all attributes after a .Session.commit call, however.
infoOptional data dictionary which will be populated into the .MapperProperty.info attribute of this object.
raiseload

if True, indicates the column should raise an error when undeferred, rather than loading the value. This can be altered at query time by using the .deferred option with raiseload=False.

New in version 1.4.
def __str__(self):

Undocumented

def _getcommitted(self, state, dict_, column, passive=attributes.PASSIVE_OFF):

Undocumented

@util.preload_module('sqlalchemy.orm.state', 'sqlalchemy.orm.strategies')
def _memoized_attr__deferred_column_loader(self):

Undocumented

@util.preload_module('sqlalchemy.orm.state', 'sqlalchemy.orm.strategies')
def _memoized_attr__raise_column_loader(self):

Undocumented

def _memoized_attr__renders_in_subqueries(self):

Undocumented

def copy(self):

Undocumented

def do_init(self):

Perform subclass-specific initialization post-mapper-creation steps.

This is a template method called by the MapperProperty object's init() method.

def instrument_class(self, mapper):

Hook called by the Mapper to the property to initiate instrumentation of the class attribute managed by this MapperProperty.

The MapperProperty here will typically call out to the attributes module to set up an InstrumentedAttribute.

This step is the first of two steps to set up an InstrumentedAttribute, and is called early in the mapper setup process.

The second step is typically the init_class_attribute step, called from StrategizedProperty via the post_instrument_class() hook. This step assigns additional state to the InstrumentedAttribute (specifically the "impl") which has been determined after the MapperProperty has determined what kind of persistence management it needs to do (e.g. scalar, object, collection, etc).

def merge(self, session, source_state, source_dict, dest_state, dest_dict, load, _recursive, _resolve_conflict_map):
Merge the attribute represented by this MapperProperty from source to destination object.
__slots__: tuple[str, ...] =
_links_to_entity: bool =

True if this MapperProperty refers to a mapped entity.

Should only be True for RelationshipProperty, False for all others.

inherit_cache: bool =

Indicate if this .HasCacheKey instance should make use of the cache key generation scheme used by its immediate superclass.

The attribute defaults to None, which indicates that a construct has not yet taken into account whether or not its appropriate for it to participate in caching; this is functionally equivalent to setting the value to False, except that a warning is also emitted.

This flag can be set to True on a particular class, if the SQL that corresponds to the object does not change based on attributes which are local to this class, and not its superclass.

See Also

:ref:`compilerext_caching` - General guideslines for setting the .HasCacheKey.inherit_cache attribute for third-party or user defined SQL constructs.

strategy_wildcard_key: str =
_orig_columns =

Undocumented

active_history =

Undocumented

columns =

Undocumented

comparator_factory =

Undocumented

deferred =

Undocumented

descriptor =

Undocumented

doc =

Undocumented

expire_on_flush =

Undocumented

group =

Undocumented

info =

Undocumented

instrument =

Undocumented

raiseload =

Undocumented

strategy_key =

Undocumented

@property
expression =

Return the primary column or expression for this ColumnProperty.

E.g.:

class File(Base):
    # ...

    name = Column(String(64))
    extension = Column(String(8))
    filename = column_property(name + '.' + extension)
    path = column_property('C:/' + filename.expression)