BetaRide BetaRide - 16 days ago 5
MySQL Question

doctrine 2.0 : use SQL timestamp

I'm looking for a way to make doctrine using

TIMESTAMP
instead of
DATETIME
for MySql.

Additionaly I need to set
ON UPDATE CURRENT_TIMESTAMP
and
CURRENT_TIMESTAMP
as default values.

I would like to have the possibility to have all this code in PHP annotations to have everything in one central place.

How can I do that?

Answer

There is no such thing like using TIMESTAMP in mysql with Doctrine. However, I fixed it myself but have to test it:

  • Create a file: Doctrine\DBAL\Types\TimestampType.php
  • Copy the code from TimeType.php into TimestampType.php
  • Rename 'Time' to 'Timestamp' in the code
  • Create a new constant, and add timestamp to the typesmap in: Doctrine\DBAL\Types\Type.php
  • Create function called getTimestampTypeDeclarationSQL in Doctrine\DBAL\Platforms\AbstractPlatform.php
  • And in that function, return TIMESTAMP

I've used yaml to create my Entities and Proxies, so use in yaml:

type: timestamp

I'm going to test this 'fix'/'workaround' now. I'll let you know.