]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- documentation cleanup in ORM including [ticket:2816]
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 7 Dec 2013 23:00:34 +0000 (18:00 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 7 Dec 2013 23:03:05 +0000 (18:03 -0500)
Conflicts:
lib/sqlalchemy/orm/mapper.py

lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/orm/session.py
lib/sqlalchemy/orm/util.py

index afc5c6e2e7ccadf9e75ed5bb919b281cf607a5ad..177e31651a223a354f798d91488c16b26446b5c9 100644 (file)
@@ -265,7 +265,9 @@ class Mapper(_InspectionAttr):
     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`.
 
     """
 
@@ -283,7 +285,9 @@ class Mapper(_InspectionAttr):
     subclass.  For single-table inheritance mappers, mapped_table
     references the base table.
 
-    See also :attr:`~.Mapper.local_table`.
+    .. seealso::
+
+        :attr:`~.Mapper.local_table`.
 
     """
 
@@ -302,7 +306,9 @@ class Mapper(_InspectionAttr):
     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`.
 
     """
 
@@ -1604,10 +1610,10 @@ class Mapper(_InspectionAttr):
         """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)
@@ -1617,10 +1623,10 @@ class Mapper(_InspectionAttr):
         """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)
@@ -1630,10 +1636,10 @@ class Mapper(_InspectionAttr):
         """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)
@@ -1643,10 +1649,10 @@ class Mapper(_InspectionAttr):
         """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)
@@ -1828,10 +1834,11 @@ class Mapper(_InspectionAttr):
         """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
@@ -1845,8 +1852,7 @@ class Mapper(_InspectionAttr):
         """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)
@@ -1855,6 +1861,11 @@ class Mapper(_InspectionAttr):
         """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`.
 
@@ -1875,6 +1886,11 @@ class Mapper(_InspectionAttr):
         """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)
index ffb8a4e03960dcd66e2465abcf5bd2a361ccc3b4..dc8b936ca4fb18777a3b40828b02b1ed4c9c9cd3 100644 (file)
@@ -2090,9 +2090,10 @@ class Session(_SessionClassMethods):
     access to the full set of persistent objects (i.e., those
     that have row identity) currently in the session.
 
-    See also:
+    .. seealso::
 
-    :func:`.identity_key` - operations involving identity keys.
+        :func:`.identity_key` - helper function to produce the keys used
+        in this dictionary.
 
     """
 
index 99349c0197a756e7495e1c73485162b8eaab963c..cc2751f2e2b3421602aed7a16032847052481e30 100644 (file)
@@ -160,31 +160,59 @@ def polymorphic_union(table_map, typecolname,
 
 
 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: