Modified DateTime doctrine is not saved
I am trying to change the DateTime field of an object using the function modify
$em = $this->getDoctrine()->getManager();
$end = $session->getEndDate();
$session->setEndDate($end->modify('+10 seconds'));
$em->persist($session);
$em->flush();
This is the setter for the $ endDate field in the Session class:
/**
* @param \DateTime $endDate
*/
public function setEndDate(\DateTime $endDate)
{
$this->endDate = $endDate;
}
Why can't end date changes persist to the database?
+3
source to share
4 answers
You need to clear it:
$em->flush($session);
Saving is only saved for an object that has not yet been created.
UPDATE:
The method modify
returns nothing, affects the instance of the object object, so you can just try:
$end = $session->getEndDate();
$end->modify('+10 seconds');
$em->flush();
Hope for this help
+5
source to share
Based on @Cerad's comments, I wonder if this will work for you:
$em = $this->getDoctrine()->getManager();
$end = new \DateTime( $session->getEndDate() );
$end->modify('+10 seconds');
$session->setEndDate( $end );
$em->persist($session);
$em->flush();
You may try. I'm not sure if this will make a difference.
0
source to share