Symfony entity - Oracle default SYSDATE not working

193 Views Asked by At

Symfony 5 + Oracle.

Entity:

/**
 * @var \DateTime
 *
 * @ORM\Column(name="CREATE_DT", type="date", nullable=false, options={"default"="SYSDATE"})
 */
private $createDt = 'SYSDATE';

Controller:

//save entity object to database (createDt property NOT passed, default must be applied)
$em->persist($obj);
$em->flush();

Error: Could not convert PHP value 'SYSDATE' of type 'string' to type 'date'. Expected one of the following types: null, DateTime (500 Internal Server Error)

How can I make Symfony apply default SYSDATE at flush?

1

There are 1 best solutions below

0
qdequippe On BEST ANSWER

You can init your date with default value directly in the constructor.

class YourEntity {

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="CREATE_DT", type="date", nullable=false)
     */
    private $createDt;

    public function __construct() {
        $this->createDt = new \Datetime();
    }
}