현재이 방법은 선택한 행을 업데이트하는 방법으로 & 업데이트를 통해 찾을 수 있습니다.doctrine 찾기 및 업데이트 코드
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();
}
그러나, 나는이 2 개 DB 작업을 (& 업데이 트를 찾을 수)가 필요로이 충분히 효율적입니다 생각하지 않습니다.
위의 코드를 최적화 할 수있는 방법이 있습니까?
당신은 여기에 답을 찾을 수 있습니다 : http://stackoverflow.com/questions/4337751/doctrine-2-update-query-with-query-builder – colburton
그것은 내게 느낌이 듭니다. 그런 다음 엔티티를 찾을 수 없을 때 특정 동작을 허용하도록 데이터베이스가 업데이트됩니다. * "교리적인 방식"*이 코드는 최적화 될 수 있다고 생각하지 않습니다. 필요한 경우 [업데이트 쿼리] (http://docs.doctrine-project.org/en/2.1/reference/dql-doctrine-query-language.html#update-queries)를 조건에 맞게 처리 할 수 있습니다. – Touki