mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Is it possible to set a field value to a database expression such as CURRENT_TIMESTAMP? #5464
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 @BabakMN on GitHub (Mar 17, 2017).
Originally assigned to: @Ocramius on GitHub.
I'd like to know if it's possible to set a field value to a database value such as CURRENT_TIMESTAMP?
One main benefit is that it allows you to maintain consistent timestamps within a transaction.
For example I would like the "creation date" of a bunch of different objects that get created within a transaction to be exactly the same as each other.
Otherwise you have to pass a specific
DateTimeinstance around, or you will get different timestamps.@Ocramius commented on GitHub (Mar 17, 2017):
This is not supported, as the ORM treats the in-memory state as authoritative, and would otherwise need to re-query data after each insert/update.
In general, you can consider support for db-side generated fields as a feature that will not land in the ORM.
The safest way to currently get a transaction-safe timestamp is to:
clockobject that you use during entity creation/updateClosing here
@ekonoval commented on GitHub (Mar 19, 2020):
But why doctrine commands still keep generating entities like this ?
http://prntscr.com/rj1y4a
Is it a bug?
I'm using 2.7 version