this :class:`.Mapper` represents. If this mapper is a
single-table inheriting mapper, local_table will be ``None``.
- See also :attr:`~.Mapper.mapped_table`.
+ .. seealso::
+
+ :attr:`~.Mapper.mapped_table`.
"""
subclass. For single-table inheritance mappers, mapped_table
references the base table.
- See also :attr:`~.Mapper.local_table`.
+ .. seealso::
+
+ :attr:`~.Mapper.local_table`.
"""
This is a *read only* attribute determined during mapper construction.
Behavior is undefined if directly modified.
- See also :func:`.configure_mappers`.
+ .. seealso::
+
+ :func:`.configure_mappers`.
"""
"""Return a namespace of all :class:`.SynonymProperty`
properties maintained by this :class:`.Mapper`.
- See also:
+ .. seealso::
- :attr:`.Mapper.attrs` - namespace of all :class:`.MapperProperty`
- objects.
+ :attr:`.Mapper.attrs` - namespace of all :class:`.MapperProperty`
+ objects.
"""
return self._filter_properties(descriptor_props.SynonymProperty)
"""Return a namespace of all :class:`.ColumnProperty`
properties maintained by this :class:`.Mapper`.
- See also:
+ .. seealso::
- :attr:`.Mapper.attrs` - namespace of all :class:`.MapperProperty`
- objects.
+ :attr:`.Mapper.attrs` - namespace of all :class:`.MapperProperty`
+ objects.
"""
return self._filter_properties(properties.ColumnProperty)
"""Return a namespace of all :class:`.RelationshipProperty`
properties maintained by this :class:`.Mapper`.
- See also:
+ .. seealso::
- :attr:`.Mapper.attrs` - namespace of all :class:`.MapperProperty`
- objects.
+ :attr:`.Mapper.attrs` - namespace of all :class:`.MapperProperty`
+ objects.
"""
return self._filter_properties(properties.RelationshipProperty)
"""Return a namespace of all :class:`.CompositeProperty`
properties maintained by this :class:`.Mapper`.
- See also:
+ .. seealso::
- :attr:`.Mapper.attrs` - namespace of all :class:`.MapperProperty`
- objects.
+ :attr:`.Mapper.attrs` - namespace of all :class:`.MapperProperty`
+ objects.
"""
return self._filter_properties(descriptor_props.CompositeProperty)
"""Return an identity-map key for use in storing/retrieving an
item from the identity map.
- row
- A ``sqlalchemy.engine.RowProxy`` instance or a
- dictionary corresponding result-set ``ColumnElement``
- instances to their values within a row.
+ :param row: A :class:`.RowProxy` instance. The columns which are mapped
+ by this :class:`.Mapper` should be locatable in the row, preferably
+ via the :class:`.Column` object directly (as is the case when a
+ :func:`.select` construct is executed), or via string names of the form
+ ``<tablename>_<colname>``.
"""
pk_cols = self.primary_key
"""Return an identity-map key for use in storing/retrieving an
item from an identity map.
- primary_key
- A list of values indicating the identifier.
+ :param primary_key: A list of values indicating the identifier.
"""
return self._identity_class, tuple(primary_key)
"""Return the identity key for the given instance, based on
its primary key attributes.
+ If the instance's state is expired, calling this method
+ will result in a database check to see if the object has been deleted.
+ If the row no longer exists,
+ :class:`~sqlalchemy.orm.exc.ObjectDeletedError` is raised.
+
This value is typically also found on the instance state under the
attribute name `key`.
"""Return the list of primary key values for the given
instance.
+ If the instance's state is expired, calling this method
+ will result in a database check to see if the object has been deleted.
+ If the row no longer exists,
+ :class:`~sqlalchemy.orm.exc.ObjectDeletedError` is raised.
+
"""
state = attributes.instance_state(instance)
return self._primary_key_from_state(state)
def identity_key(*args, **kwargs):
- """Get an identity key.
+ """Generate "identity key" tuples, as are used as keys in the
+ :attr:`.Session.identity_map` dictionary.
- Valid call signatures:
+ This function has several call styles:
* ``identity_key(class, ident)``
- class
- mapped class (must be a positional argument)
+ This form receives a mapped class and a primary key scalar or
+ tuple as an argument.
- ident
- primary key, if the key is composite this is a tuple
+ E.g.::
+
+ >>> identity_key(MyClass, (1, 2))
+ (<class '__main__.MyClass'>, (1, 2))
+
+ :param class: mapped class (must be a positional argument)
+ :param ident: primary key, may be a scalar or tuple argument.
* ``identity_key(instance=instance)``
- instance
- object instance (must be given as a keyword arg)
+ This form will produce the identity key for a given instance. The
+ instance need not be persistent, only that its primary key attributes
+ are populated (else the key will contain ``None`` for those missing
+ values).
+
+ E.g.::
+
+ >>> instance = MyClass(1, 2)
+ >>> identity_key(instance=instance)
+ (<class '__main__.MyClass'>, (1, 2))
+
+ In this form, the given instance is ultimately run though
+ :meth:`.Mapper.identity_key_from_instance`, which will have the
+ effect of performing a database check for the corresponding row
+ if the object is expired.
+
+ :param instance: object instance (must be given as a keyword arg)
* ``identity_key(class, row=row)``
- class
- mapped class (must be a positional argument)
+ This form is similar to the class/tuple form, except is passed a
+ database result row as a :class:`.RowProxy` object.
+
+ E.g.::
+
+ >>> row = engine.execute("select * from table where a=1 and b=2").first()
+ >>> identity_key(MyClass, row=row)
+ (<class '__main__.MyClass'>, (1, 2))
- row
- result proxy row (must be given as a keyword arg)
+ :param class: mapped class (must be a positional argument)
+ :param row: :class:`.RowProxy` row returned by a :class:`.ResultProxy`
+ (must be given as a keyword arg)
"""
if args: