mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Why is Id AutoGenerated anew on UPDATE with Relation using Symfony Doctrine? #6843
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 @dVVIIb on GitHub (Oct 4, 2021).
Bug Report
Summary
This has been rather difficult to diagnose especially as I was dealing with some complicated layered code. If I was sure, I would have filed a bug with Doctrine before now, but I wanted to first make sure I'm not making some glaring mistake or such, in implementation, so I posted a question on StackOverflow, first, but still have no answer.
I have painstakingly tried to reduce the code to a simplified working example. On my test database tables, there are additional columns that are not referred to in the demo code.
Current behavior
When this route ("/") is triggered, the record is updated and the old Id is displayed. But after the update, checking the database shows that the record now has a newly Auto-Generated Id, that comes after the last previous record in the table. Note that this is on UPDATE and not INSERT. The above is, as shown, OneToOne. I haven't yet checked whether the same issue occurs for OneToMany/ManyToOne Associations.
Of course, I realize this occurs because I'm using a new Associated child entity here, and can work around this by using an existing child object if any, but there may be a use case for a new child association (esp. if one wasn't assigned on persisting new parent Record), depending on application requirements, so a proper solution is needed anyway, I think.
How to reproduce
Please see above code samples and below:
These tables and above code are not completely compatible AS IS. Shown here in full, if necessary to help resolve the issue or if relevant in any way. You may need to exclude some columns, or add dummy columns to the entities in above code.
Expected behavior
(Record/row) Id should not be altered during update.
One urgent project of mine is held up due to this issue. Any assistance/clarification is appreciated.
Thank you.
@derrabus commented on GitHub (Oct 4, 2021):
I'm moving this issue to discussions because we have stopped providing bugfix support for ORM 2.4 six years ago.