Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
Doctrine modified DateTime is not persisted

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?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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

about 4 years ago · Santiago Trujillo Report

0

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

about 4 years ago · Santiago Trujillo Report

0

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();
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!