mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
There seems to be a bug when updating the object #6644
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 @StasToken on GitHub (Mar 6, 2021).
I encountered an obvious bug when Doctrine does not save the model value to the database when updating the object
use:
I use it in my symfony 5 project (I will give an abbreviated model just to reflect the whole point)
I want to update the field with time:
Note that 1 day was added to the DateTime object (Note that the object ID doctrine/DoctrineBundle#1001 and doctrine/DoctrineBundle#1001 is the same object)
The procedure for saving the change to the database was called, but the object was not saved. The UPDATE request was not executed (I looked at the logs, it was not executed, I did not even try)
I racked my head for a long time what's the matter, I somehow came up with the idea that Doctrine does not save the object because it does not know that it has changed, since the DateTime object itself remained the same - it was just modified I decided to check it by simply creating a new object
Note that the object IDs [#1001 and doctrine/DoctrineBundle#96] are now different
Now saving to the database goes as expected!
WTF - It's very similar to the fact that Doctrine does not know that the object has been updated, I do not know how normal this is, to be honest it looks more like a jamb.. - in general, I decided to inform the developers about this behavior, because it can confuse other people.
@beberlei commented on GitHub (Mar 6, 2021):
Its not a bug, datetime objects are compared by reference not by value. This is documented afaik
@StasToken commented on GitHub (Mar 6, 2021):
And how can I make some kind of forced save? to not make a clone of the object and then it's stupid...
@beberlei commented on GitHub (Mar 6, 2021):
You can use datetimeimmutablw instead then modify returns a new instance