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 :

Classe « QueryEvents »

Méthode sqlalchemy.orm.QueryEvents.before_compile_delete

Signature de la méthode before_compile_delete

def before_compile_delete(self, query, delete_context) 

Description

before_compile_delete.__doc__

Allow modifications to the :class:`_query.Query` object within
:meth:`_query.Query.delete`.

.. container:: event_signatures

     Example argument forms::

        from sqlalchemy import event


        @event.listens_for(SomeQuery, 'before_compile_delete')
        def receive_before_compile_delete(query, delete_context):
            "listen for the 'before_compile_delete' event"

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


.. deprecated:: 1.4  The :meth:`_orm.QueryEvents.before_compile_delete`
   event is superseded by the much more capable
   :meth:`_orm.SessionEvents.do_orm_execute` hook.

Like the :meth:`.QueryEvents.before_compile` event, this event
should be configured with ``retval=True``, and the modified
:class:`_query.Query` object returned, as in ::

    @event.listens_for(Query, "before_compile_delete", retval=True)
    def no_deleted(query, delete_context):
        for desc in query.column_descriptions:
            if desc['type'] is User:
                entity = desc['entity']
                query = query.filter(entity.deleted == False)
        return query

:param query: a :class:`_query.Query` instance; this is also
 the ``.query`` attribute of the given "delete context"
 object.

:param delete_context: a "delete context" object which is
 the same kind of object as described in
 :paramref:`.QueryEvents.after_bulk_delete.delete_context`.

.. versionadded:: 1.2.17

.. seealso::

    :meth:`.QueryEvents.before_compile`

    :meth:`.QueryEvents.before_compile_update`