http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/batch-processing.html#batch-processing
我的例子:
我的例子:
$cities=Array(); $cities=Array(); $em = $this->getDoctrine()->getEntityManager(); $qb=$em->getRepository('AcmeBannieresBundle:TVille')->createQueryBuilder('tv'); //$cities=$qb->getQuery()->execute(); $iterableResult =$qb->getQuery()->iterate(); $j=0; while (($row = $iterableResult->next()) !== false) { $city=$row[0]; //$city=new TVille(); for ($p=1;$p++;$p<9){ $banner=new BannerCity(); $banner->setCity($city); $banner->setPosition($p); //$city->addBannerCity($banner); $em->persist($banner); } //$em->persist($city); $j++; if ($j>100){ $em->flush(); $em->clear(); // Detaches all objects from Doctrine! $j=0; } //$em->detach($city); } // $em->flush(); return array();
评论
发表评论