.. _session_persistence_mapper:
-Mapper-level Events
-^^^^^^^^^^^^^^^^^^^
+Mapper-level Flush Events
+^^^^^^^^^^^^^^^^^^^^^^^^^
-In addition to the flush-level hooks, there is also a suite of hooks
-that are more fine-grained, in that they are called on a per-object
-basis and are broken out based on INSERT, UPDATE or DELETE. These
-are the mapper persistence hooks, and they too are very popular,
-however these events need to be approached more cautiously, as they
-proceed within the context of the flush process that is already
-ongoing; many operations are not safe to proceed here.
+In addition to the flush-level hooks, there is also a suite of hooks that are
+more fine-grained, in that they are called on a per-object basis and are broken
+out based on INSERT, UPDATE or DELETE within the flush process. These are the
+mapper persistence hooks, and they too are very popular, however these events
+need to be approached more cautiously, as they proceed within the context of
+the flush process that is already ongoing; many operations are not safe to
+proceed here.
The events are:
* :meth:`.MapperEvents.before_delete`
* :meth:`.MapperEvents.after_delete`
+.. note::
+
+ It is important to note that these events apply **only** to the
+ :ref:`session flush operation <session_flushing>` , and **not** to the
+ ORM-level INSERT/UPDATE/DELETE functionality described at
+ :ref:`orm_expression_update_delete`. To intercept ORM-level DML, use the
+ :meth:`_orm.SessionEvents.do_orm_execute` event.
+
Each event is passed the :class:`_orm.Mapper`,
the mapped object itself, and the :class:`_engine.Connection` which is being
used to emit an INSERT, UPDATE or DELETE statement. The appeal of these
"""Receive an object instance before an INSERT statement
is emitted corresponding to that instance.
+ .. note:: this event **only** applies to the
+ :ref:`session flush operation <session_flushing>`
+ and does **not** apply to the ORM DML operations described at
+ :ref:`orm_expression_update_delete`. To intercept ORM
+ DML events, use :meth:`_orm.SessionEvents.do_orm_execute`.
+
This event is used to modify local, non-object related
attributes on the instance before an INSERT occurs, as well
as to emit additional SQL statements on the given
"""Receive an object instance after an INSERT statement
is emitted corresponding to that instance.
+ .. note:: this event **only** applies to the
+ :ref:`session flush operation <session_flushing>`
+ and does **not** apply to the ORM DML operations described at
+ :ref:`orm_expression_update_delete`. To intercept ORM
+ DML events, use :meth:`_orm.SessionEvents.do_orm_execute`.
+
This event is used to modify in-Python-only
state on the instance after an INSERT occurs, as well
as to emit additional SQL statements on the given
"""Receive an object instance before an UPDATE statement
is emitted corresponding to that instance.
+ .. note:: this event **only** applies to the
+ :ref:`session flush operation <session_flushing>`
+ and does **not** apply to the ORM DML operations described at
+ :ref:`orm_expression_update_delete`. To intercept ORM
+ DML events, use :meth:`_orm.SessionEvents.do_orm_execute`.
+
This event is used to modify local, non-object related
attributes on the instance before an UPDATE occurs, as well
as to emit additional SQL statements on the given
"""Receive an object instance after an UPDATE statement
is emitted corresponding to that instance.
+ .. note:: this event **only** applies to the
+ :ref:`session flush operation <session_flushing>`
+ and does **not** apply to the ORM DML operations described at
+ :ref:`orm_expression_update_delete`. To intercept ORM
+ DML events, use :meth:`_orm.SessionEvents.do_orm_execute`.
+
This event is used to modify in-Python-only
state on the instance after an UPDATE occurs, as well
as to emit additional SQL statements on the given
"""Receive an object instance before a DELETE statement
is emitted corresponding to that instance.
+ .. note:: this event **only** applies to the
+ :ref:`session flush operation <session_flushing>`
+ and does **not** apply to the ORM DML operations described at
+ :ref:`orm_expression_update_delete`. To intercept ORM
+ DML events, use :meth:`_orm.SessionEvents.do_orm_execute`.
+
This event is used to emit additional SQL statements on
the given connection as well as to perform application
specific bookkeeping related to a deletion event.
"""Receive an object instance after a DELETE statement
has been emitted corresponding to that instance.
+ .. note:: this event **only** applies to the
+ :ref:`session flush operation <session_flushing>`
+ and does **not** apply to the ORM DML operations described at
+ :ref:`orm_expression_update_delete`. To intercept ORM
+ DML events, use :meth:`_orm.SessionEvents.do_orm_execute`.
+
This event is used to emit additional SQL statements on
the given connection as well as to perform application
specific bookkeeping related to a deletion event.