public function getRegionTeams(Region $region) { $teams = $this->whoscored->loadStatistics('regionteams', array('id' => $region->getWsId())); foreach ($teams as $team) { if ($this->em->getRepository('AppBundle:Team')->findOneByWsId($team[0]) !== null) { continue; } $ret = new Team(); $ret->setWsId($team[0]); $ret->setName($team[1]); $this->em->persist($ret); unset($ret); } $this->em->flush(); }