Skip to content
1 min read

Doctrine 2 preUpdate event

Doctrine 2 preUpdate event

The doctrine project logo.

Doctrine logo source: doctrine-project.org.

Some time ago I was implementing an event listener for Doctrine 2. While testing it, I ran into an issue where events would not fire, which was frustrating. More specifically, saving entities with events such as preUpdate did not seem to work.

The answer could not be found in the documentation (or I could not find it then). Inside the executeUpdates function in doctrine2/lib/Doctrine/ORM/UnitOfWork.php it says:

if (!empty($this->entityChangeSets[$oid])) {
  $persister->update($entity);
}

This means it checks whether there are any model changes and, only then, updates the entity and triggers the event.

I opened a pull request to clarify the documentation.