I have a problem with this code:
$elements = $em
->getRepository('AppBundle:MyElementsEntity')
->findByLinkType($linkType); // This returns SEVEN elements
foreach ($elements as $e) {
$beginDate = $e->getBeginDate();
$beginDate->setTime($begin->format('H'), $begin->format('i'));
$endDate = $e->getEndDate();
$endDate->setTime($end->format('H'), $end->format('i'));
$e->setEndDate($endDate);
$e->setBeginDate($beginDate);
$em->persist($e);
$em->flush();
}
As you can see, it fetches some elements from the database, changes the time from the beginDate and endDate fields ($begin and $end are DateTime objects), and tries to update the database.
The code doesn't throw any exception, but it doesn't work. When I look at Symfony2's log (app/logs/dev.log), there are the SQL statements to fetch the data, alter sessions, etc, but there isn't any update statement.
And I have another function, that only updates one element each time, and this is working correctly.
What I'm doing wrong? Why I can batch-update the previous selected elements? I'm missing something important?
** UPDATE **
I've done some modifications to the code, but it still doesn't update the entities to the database:
- I've removed the
$em->persist($e)
call. - I've moved the
$em->flush()
call to outside theforeach
loop. - I've removed the transactional code (
beginTransaction()
,commit()
androllback()
calls)
But the problem is still the same: Doctrine doesn't send any UPDATE statement to the server (FYI, is an Oracle 11g).