我在Symfony2控制器上有关于$em->flush()
的问题。 Symfony2 flush()实体
$v = $em->getRepository("ApplicationAdminBundle:VehiculeCompute")->findAll();
foreach ($v as $vehicule) {
[...]
$somme = {"compute before"};
$veh = $em->getRepository("ApplicationAdminBundle:VehiculeCompute")->find($vehicule->getIdvehicules());
$veh->setTaxeadditionnelle($somme);
$em->flush();
$total++;
}
因此,要执行这个循环,我的脚本需要很长的时间,因为我已经在我的桌边站〜40000个VEHICULES。
我想$em->flush()
在每个循环中没有必要...
$v = $em->getRepository("ApplicationAdminBundle:VehiculeCompute")->findAll();
$k = 0;
foreach ($v as $vehicule) {
[...]
$somme = {"compute before"};
$veh[$k] = $em->getRepository("ApplicationAdminBundle:VehiculeCompute")->find($vehicule->getIdvehicules());
$veh[$k]->setTaxeadditionnelle($somme);
$total++;
}
$em->flush(); // Flush all of vehicule update ?!
unset($veh);
这个版本可以正常工作? 谢谢。
我最初的想法是,这是一个ORM不合适的场合。您应该使用Doctrine查询生成器来直接对话DBAL层。 – lonesomeday 2014-08-29 08:49:22
有关于Doctrine文档中批处理的一些信息 - http://docs.doctrine-project.org/zh/2.0.x/reference/batch-processing.html#bulk-inserts – qooplmao 2014-08-29 08:54:15
@Prisoner'persist'是为了坚持新实体在更新已经存在的实体时,不应该使用它。 – 2014-08-29 09:18:14