New record after findBy #5216

Closed
opened 2026-01-22 15:01:45 +01:00 by admin · 2 comments
Owner

Originally created by @frank-herbert on GitHub (Aug 11, 2016).

Originally assigned to: @Ocramius on GitHub.

Doctrine is creating a new record after when you get the results using "findBy".

$collection = $this->em
    ->getRepository("MyBundle:MyEntity")
    ->findBy(array('Status' => null));

foreach ($collection as $item) {
    $item->setTimestamp(\DateTime::createFromFormat('U.u', microtime(true)));
    $item->setStatus('DONE');

    $this->em->persist($item);
    $this->em->flush();
}
Originally created by @frank-herbert on GitHub (Aug 11, 2016). Originally assigned to: @Ocramius on GitHub. Doctrine is creating a new record after when you get the results using "findBy". ``` php $collection = $this->em ->getRepository("MyBundle:MyEntity") ->findBy(array('Status' => null)); foreach ($collection as $item) { $item->setTimestamp(\DateTime::createFromFormat('U.u', microtime(true))); $item->setStatus('DONE'); $this->em->persist($item); $this->em->flush(); } ```
admin added the Invalid label 2026-01-22 15:01:45 +01:00
admin closed this issue 2026-01-22 15:01:46 +01:00
Author
Owner

@Ocramius commented on GitHub (Aug 11, 2016):

That's not sufficient information to debug your issue. What is being created? What do setTimestamp and setStatus do? Is $item a managed entity at all times? Are sub-entries created?

@Ocramius commented on GitHub (Aug 11, 2016): That's not sufficient information to debug your issue. What is being created? What do `setTimestamp` and `setStatus` do? Is `$item` a managed entity at all times? Are sub-entries created?
Author
Owner

@frank-herbert commented on GitHub (Aug 11, 2016):

Thank you for your help, Ocramius.

$item was empty before Doctrine persist().

My mistake. Sorry.

@frank-herbert commented on GitHub (Aug 11, 2016): Thank you for your help, Ocramius. $item was empty before Doctrine persist(). My mistake. Sorry.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5216