Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing list "Lifecycle Events" #9243

Merged
merged 15 commits into from
Dec 28, 2021
Prev Previous commit
Next Next commit
prePersist
  • Loading branch information
ThomasLandauer authored Dec 12, 2021
commit e4331989c1d095a3f90b16f9c568dafc642fcf33
23 changes: 11 additions & 12 deletions docs/en/reference/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,7 @@ events during the life-time of their registered entities.



- ``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 (i.e. it does not trigger on future updates).

- ``preUpdate`` - The ``preUpdate`` event occurs before the database
update operations to entity data. It is not called for a DQL
``UPDATE`` statement nor when the computed changeset is empty.
Expand Down Expand Up @@ -523,29 +520,31 @@ that (prior to version 2.4) you do not have access to the
prePersist
~~~~~~~~~~

There are two ways for the ``prePersist`` event to be triggered.
One is obviously when you call ``EntityManager#persist()``. The
event is also called for all cascaded associations.
There are two ways for the ``prePersist`` event to be triggered:

There is another way for ``prePersist`` to be called, inside the
- One is obviously when you call ``EntityManager::persist()``. The
event is also called for all :ref:`cascaded associations<transitive-persistence>`.
- The other is inside the
``flush()`` method when changes to associations are computed and
this association is marked as cascade persist. Any new entity found
this association is marked as :ref:`cascade: persist<transitive-persistence>`. Any new entity found
during this operation is also persisted and ``prePersist`` called
on it. This is called "persistence by reachability".
on it. This is called :ref:`persistence by reachability<persistence-by-reachability>`.

In both cases you get passed a ``LifecycleEventArgs`` instance
which has access to the entity and the entity manager.

The following restrictions apply to ``prePersist``:
This event is only triggered on *initial* persist of an entity
(i.e. it does not trigger on future updates).

The following restrictions apply to ``prePersist``:

- If you are using a PrePersist Identity Generator such as
sequences the ID value will *NOT* be available within any
PrePersist events.
- Doctrine will not recognize changes made to relations in a prePersist
event. This includes modifications to
collections such as additions, removals or replacement.

.. _reference-events-pre-remove:

preRemove
Expand Down