Doctrine 2.0: Use SQL Timestamp

I am looking for a way to doctrine using TIMESTAMPinstead DATETIMEfor MySql.

Additionally I need to set ON UPDATE CURRENT_TIMESTAMPand CURRENT_TIMESTAMPas default values.

I would like to be able to have all this code in PHP annotations in order to have everything in one central place.

How can i do this?

+5
source share
7 answers

There is no such thing as using TIMESTAMPin mysql using Doctrine. However, I fixed it myself, but I have to check:

  • Create file: Doctrine\DBAL\Types\TimestampType.php
  • Copy code from TimeType.phptoTimestampType.php
  • Rename 'Time' to 'Timestamp' in code
  • Create a new constant and add a timestamp to the type table in: Doctrine\DBAL\Types\Type.php
  • getTimestampTypeDeclarationSQL Doctrine\DBAL\Platforms\AbstractPlatform.php
  • TIMESTAMP

yaml , yaml:

type: timestamp

"" / " ". .

+3

, , - , WRONG ( TIMESTAMP - datetime)

, ,

 * @ORM\Column(type="datetime", nullable=false)
 * @ORM\Version

, Doctrine TIMESTAMP DEFAULT CURRENT_TIMESTAMP, \DateTime.

CTOP (Credits to Original Poster)

+10

@ , . . , :

GitHub:

.. , , , . , .

+2
/** @ORM\Column(type="datetime", nullable=false ) */
    protected $created;

timestamp return datetime

 public function __construct()
        {
            $this->created = new \DateTime();

        }
+1

/** * @Column(type="datetime", options={"default": 0}) * @version=true */ private $data;

sql : data TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL

2.5.4

0

@ORM\Version , , .

0

Daniel Criconet,

@ORM\Column(type="datetime", columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")

MySQL TIMESTAMP DATETIME.

YAML . .

0

All Articles