mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Creating an entity inside a PreFlush is throwing an error INSERT VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
#6682
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 @VincentLanglet on GitHub (Apr 6, 2021).
I have an entity
Subscriptionin OtO withAddressandLeadwhich is also in OtO withAddress.In the Subscription, I have the following preFlush
Everything works fine when
$lead->getAddres()is not null ; the address is updated.But when it's null (ie the code
new Address();is executed), I was expecting that a new address could be created and set.Instead, I'm getting the following error:
Is this a bug ?
@beberlei commented on GitHub (Apr 6, 2021):
No, not every event can do everything, you probably need to do this in the general
onFlushevent@VincentLanglet commented on GitHub (Apr 7, 2021):
I just discovered that if the address of the subscription is new, it always works.
But if the address already exist for the subscription and is updated, it doesnt work if I have to create a new address.
I would have prefer to avoid creating a Listener and playing more with the
UnitOfWorkAPI. According to the doc, I'll needcomputeChangeSetandrecomputeSingleEntityChangeSet, but these methods are marked as@internal.@VincentLanglet commented on GitHub (Apr 7, 2021):
I just tried an
onFlushevent.The issue I get is that
$unitOfWork->getOriginalEntityData()is not returning the old value anymore...@VincentLanglet commented on GitHub (Apr 7, 2021):
It does work in a PreFlush event if I call
@VincentLanglet commented on GitHub (Apr 9, 2021):
I solved my issue, but I need
computeChangeSetso I created https://github.com/doctrine/orm/pull/8600thanks @beberlei