]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
doc updates
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Jan 2011 18:55:27 +0000 (13:55 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Jan 2011 18:55:27 +0000 (13:55 -0500)
doc/build/orm/loading.rst
lib/sqlalchemy/orm/events.py

index 3ef2afa44c98e7272fd17afe0b7068f04a36549e..b62fac48844378581f27911169aa157dc2f8a087 100644 (file)
@@ -122,7 +122,7 @@ To reference a relationship that is deeper than one level, separate the names by
     session.query(Parent).options(joinedload('foo.bar.bat')).all()
 
 When using dot-separated names with :func:`~sqlalchemy.orm.joinedload` or
-:func:`~sqlalchemy.orm.subqueryload`, option applies **only** to the actual
+:func:`~sqlalchemy.orm.subqueryload`, the option applies **only** to the actual
 attribute named, and **not** its ancestors. For example, suppose a mapping
 from ``A`` to ``B`` to ``C``, where the relationships, named ``atob`` and
 ``btoc``, are both lazy-loading. A statement like the following:
@@ -131,21 +131,26 @@ from ``A`` to ``B`` to ``C``, where the relationships, named ``atob`` and
 
     session.query(A).options(joinedload('atob.btoc')).all()
 
-will load only ``A`` objects to start.  When the ``atob`` attribute on each ``A`` is accessed, the returned ``B`` objects will *eagerly* load their ``C`` objects.
+will load only ``A`` objects to start. When the ``atob`` attribute on each
+``A`` is accessed, the returned ``B`` objects will *eagerly* load their ``C``
+objects.
 
-Therefore, to modify the eager load to load both ``atob`` as well as ``btoc``, place joinedloads for both:
+Therefore, to modify the eager load to load both ``atob`` as well as ``btoc``,
+place joinedloads for both:
 
 .. sourcecode:: python+sql
 
     session.query(A).options(joinedload('atob'), joinedload('atob.btoc')).all()
 
-or more simply just use :func:`~sqlalchemy.orm.joinedload_all` or :func:`~sqlalchemy.orm.subqueryload_all`:
+or more simply just use :func:`~sqlalchemy.orm.joinedload_all` or
+:func:`~sqlalchemy.orm.subqueryload_all`:
 
 .. sourcecode:: python+sql
 
     session.query(A).options(joinedload_all('atob.btoc')).all()
 
-There are two other loader strategies available, **dynamic loading** and **no loading**; these are described in :ref:`largecollections`.
+There are two other loader strategies available, **dynamic loading** and **no
+loading**; these are described in :ref:`largecollections`.
 
 The Zen of Eager Loading
 -------------------------
index 8e4d4a1470445c2180615b736dda8f4aef58f6bd..36f4a43fb00d852e2abb1033b37d6b2b63126237 100644 (file)
@@ -62,8 +62,43 @@ class InstrumentationEvents(event.Events):
 class InstanceEvents(event.Events):
     """Define events specific to object lifecycle.
 
-    Instance-level don't automatically propagate their associations
-    to subclasses.
+    e.g.::
+
+        from sqlalchemy import event
+
+        def my_load_listener(target, context):
+            print "on load!"
+
+        event.listen(SomeMappedClass, 'load', my_load_listener)
+
+    Available targets include mapped classes, instances of
+    :class:`.Mapper` (i.e. returned by :func:`.mapper`,
+    :func:`.class_mapper` and similar), as well as the
+    :class:`.Mapper` class and :func:`.mapper` function itself
+    for global event reception::
+
+        from sqlalchemy.orm import mapper
+
+        def some_listener(target, context):
+            log.debug("Instance %s being loaded" % target)
+
+        # attach to all mappers
+        event.listen(mapper, 'load', some_listener)
+
+    Instance events are closely related to mapper events, but
+    are more specific to the instance and its instrumentation,
+    rather than its system of persistence.
+
+    When using :class:`.InstanceEvents`, several modifiers are
+    available to the :func:`.event.listen` function.
+
+    :param propagate=False: When True, the event listener should 
+       be applied to all inheriting mappers as well as the 
+       mapper which is the target of this listener.
+    :param raw=False: When True, the "target" argument passed
+       to applicable event listener functions will be the 
+       instance's :class:`.InstanceState` management
+       object, rather than the mapped instance itself.
 
     """
     @classmethod