I try to modify DateTime field of the object with modify
function
$em = $this->getDoctrine()->getManager();
$end = $session->getEndDate();
$session->setEndDate($end->modify('+10 seconds'));
$em->persist($session);
$em->flush();
This is setter for $endDate field in Session class:
/**
* @param \DateTime $endDate
*/
public function setEndDate(\DateTime $endDate)
{
$this->endDate = $endDate;
}
Why end date changes can't be persisted to database?
Doctrine won't save changes to the existing DateTime instance (due to the internals of PHP's equality testing I think)
If you clone the object and then set it back, should work. Or clone it in the setter?
See Doctrine2 ORM does not save changes to a DateTime field
You need to flush it:
$em->flush($session);
The persist is only for entity not yet created.
UPDATE:
The modify
method don't return anything, affect the specify object instance, so you can simply try:
$end = $session->getEndDate();
$end->modify('+10 seconds');
$em->flush();
Hope this help
You need to add merge or flush to save the update
$end = $session->getEndDate();
$session->setEndDate($end->modify('+10 seconds'));
$em->persist($session);
$em->flush();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With