I
I
Igor2020-03-06 08:42:24
symfony
Igor, 2020-03-06 08:42:24

An event for an entity before it is updated?

The task is banal, before updating the entity, call the method.

At the initial save, the prePersist
event is triggered. Subsequent persist do not channel, this is stated in the documentation

prePersist - The prePersist event occurs for a given entity before the respective EntityManager persist operation for that entity is executed. It should be noted that this event is only triggered on initial persist of an entity (ie it does not trigger on future updates).


Now I want to listen for object changes.
What do you advise?

app.listeners.category.save_image_in_listener:
    class: App\Listeners\Category\SaveImageInListener
    tags:
      - name: 'doctrine.orm.entity_listener'
        event: 'prePersist'
        method: 'save'
        entity: App\Entity\CategoryProduct
        lazy: true
      - name: 'doctrine.orm.entity_listener'
        event: 'preUpdate'    # не работает
        method: 'save'
        entity: App\Entity\CategoryProduct
        lazy: true


Now while I use event postLoad
But it works repeatedly.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question