Could someone tell me how to add default value on datetime column? I can\'t do this like this:
protected $registration_date = date(\"Y-m-d H:i:s\", time());
You map your property as DateTime type then set the value in the constructor using a new DateTime instance:
/**
* @Entity
* @Table(name="...")
*/
class MyEntity
{
/** @Column(type="datetime") */
protected $registration_date;
public function __construct()
{
$this->registration_date = new DateTime();
}
}
This works as the constructor of a persisted class is not called upon hydration.