Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé
Classe « MapperEvents »

Méthode sqlalchemy.orm.MapperEvents.before_insert

Signature de la méthode before_insert

def before_insert(self, mapper: 'Mapper[_O]', connection: 'Connection', target: '_O') -> 'None' 

Description

help(MapperEvents.before_insert)

Receive an object instance before an INSERT statement
is emitted corresponding to that instance.

.. container:: event_signatures

     Example argument forms::

        from sqlalchemy import event


        @event.listens_for(SomeClass, 'before_insert')
        def receive_before_insert(mapper, connection, target):
            "listen for the 'before_insert' event"

            # ... (event handling logic) ...


.. 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
connection.

The event is often called for a batch of objects of the
same class before their INSERT statements are emitted at
once in a later step. In the extremely rare case that
this is not desirable, the :class:`_orm.Mapper` object can be
configured with ``batch=False``, which will cause
batches of instances to be broken up into individual
(and more poorly performing) event->persist->event
steps.

.. warning::

    Mapper-level flush events only allow **very limited operations**,
    on attributes local to the row being operated upon only,
    as well as allowing any SQL to be emitted on the given
    :class:`_engine.Connection`.  **Please read fully** the notes
    at :ref:`session_persistence_mapper` for guidelines on using
    these methods; generally, the :meth:`.SessionEvents.before_flush`
    method should be preferred for general on-flush changes.

:param mapper: the :class:`_orm.Mapper` which is the target
 of this event.
:param connection: the :class:`_engine.Connection` being used to
 emit INSERT statements for this instance.  This
 provides a handle into the current transaction on the
 target database specific to this instance.
:param target: the mapped instance being persisted.  If
 the event is configured with ``raw=True``, this will
 instead be the :class:`.InstanceState` state-management
 object associated with the instance.
:return: No return value is supported by this event.

.. seealso::

    :ref:`session_persistence_events`



Vous êtes un professionnel et vous avez besoin d'une formation ? Sensibilisation à
l'Intelligence Artificielle
Voir le programme détaillé