mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Cannot persist an entity during onFlush #7491
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @yann-eugone on GitHub (Mar 27, 2025).
Bug Report
Summary
Not able to persist a new entity in the
onFlushlistener.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
AuditEvententity that should be created every time an entity is updated.@mpdude commented on GitHub (Mar 30, 2025):
#10900 is related.
Are you seeing #10869 here?
@yann-eugone commented on GitHub (Mar 31, 2025):
Not sure it is related, not doing any
flushduring the event listenerTried to downgrade
doctrine/ormon the project, never been able to see it work as expected@yann-eugone commented on GitHub (Apr 1, 2025):
I think I found the reason why it do fails
My model is not that simple I wrote in the description
I do have an
AuditEvententity that represent an update eventBut that entity has a collection of to
AuditEventRelationentities, that represent payload parts when updated value are entities and not scalarThe exception I get with the
persiststrategy is when Doctrine try to insert these relationsI had to manually persist these relations to in order to make it work
5dac0ce503I still have no idea how to fix the
recordstrategy@yann-eugone commented on GitHub (Apr 2, 2025):
I believe I've found a solution to the problem I've faced
You can close it if you want
Is still believe that the error was very unclear