Currently, this is the way, how I update a selected row, through find & update.
private function turnOnLight($entity_manager, $model, $year)
{
// Is this an optimized way to update a single column?
// It seems not as we need 2 rounds DB communication trip.
$car = $entity_manager->findOneBy(array(
'model' => $model,
'year' => $year,
'light' => 0
));
if (is_null($car)) {
return;
}
$car->light = 1;
$entity_manager->persist($car);
$entity_manager->flush();
}
However, I don't feel this is efficient enough, as it requires 2 DB operations (find & update).
Is there any way to optimize the above code?