You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not able to persist a new entity in the onFlush listener.
Current behavior
When using EntityManager::persist() along with UnitOfWork::computeChangeSet(), I get a SQL syntax error: the insert query does not have any parameter bound.
When using Collection::add() along with UnitOfWork::recomputeSingleEntityChangeSet(), nothing happens: the entity is never saved.
Expected behavior
Regarding the documentation, we should be able to persist new entities, on their own, or using collections:
The following restrictions apply to the onFlush event:
If you create and persist a new entity in onFlush, then calling EntityManager::persist() is not enough. You have to execute an additional call to $unitOfWork->computeChangeSet($classMetadata, $entity).
Changing primitive fields or associations requires you to explicitly trigger a re-computation of the changeset of the affected entity. This can be done by calling $unitOfWork->recomputeSingleEntityChangeSet($classMetadata, $entity).
Not sure it is related, not doing any flush during the event listener
Tried to downgrade doctrine/orm on the project, never been able to see it work as expected
Bug Report
Summary
Not able to persist a new entity in the
onFlush
listener.Current behavior
When using
EntityManager::persist()
along withUnitOfWork::computeChangeSet()
, I get aSQL syntax error
: the insert query does not have any parameter bound.When using
Collection::add()
along withUnitOfWork::recomputeSingleEntityChangeSet()
, nothing happens: the entity is never saved.Expected behavior
Regarding the documentation, we should be able to persist new entities, on their own, or using collections:
How to reproduce
I created a pretty simple project with my use case
https://github.com/yann-eugone/doctrine-persist-in-onflush
The idea is that I have a
AuditEvent
entity that should be created every time an entity is updated.The text was updated successfully, but these errors were encountered: