Exemple #1
0
 public function load(ObjectManager $manager)
 {
     $faker = Factory::create();
     for ($i = 1; $i <= 24; $i++) {
         $team = new Team();
         $team->setInfo($faker->text(2000));
         $country = $this->getReference("country {$i}");
         $team->setCountry($country);
         $this->setReference("team {$i}", $team);
         $manager->persist($team);
         $manager->flush();
         for ($k = 1; $k <= 11; $k++) {
             $player = new Player();
             $player->setFirstName($faker->firstNameMale);
             $player->setLastName($faker->lastName);
             $player->setBiography($faker->text(200));
             $player->setDateOfBirthday($faker->date('Y-m-d'));
             $player->setTeam($team);
             $team->getPlayers()->add($player);
             $manager->persist($player);
         }
         // the same for coaches
         for ($k = 1; $k <= 5; $k++) {
             $coach = new Coach();
             $coach->setName($faker->name);
             $coach->setBiography($faker->text(200));
             $coach->setTeam($team);
             $team->getCoaches()->add($coach);
             $manager->persist($coach);
         }
     }
     $manager->flush();
 }