Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda