コード例 #1
0
 public function load(ObjectManager $manager)
 {
     $ingredientNames = ['Leek', 'Carrot', 'Potato', 'Green Lentils', 'Celeriac'];
     foreach ($ingredientNames as $ingredientName) {
         $ingredient = new Ingredient();
         $ingredient->setName($ingredientName);
         $ingredient->setDescription('This is yummi');
         $manager->persist($ingredient);
         $this->addReference('ingredient-' . $this->toReferenceString($ingredientName), $ingredient);
     }
     $manager->flush();
 }
コード例 #2
0
 public function postPersist(Recipe $recipe, LifecycleEventArgs $event)
 {
     if (count($recipe->getIngredients()) < 1) {
         return;
     }
     $entityManager = $event->getEntityManager();
     $ingredient = new Ingredient();
     $ingredient->setName('Salt');
     $ingredient->setDescription('Salt');
     $entityManager->persist($ingredient);
     $recipe->setCreatedAt(new \DateTime());
     $recipe->addIngredient($ingredient);
     $entityManager->persist($recipe);
     $entityManager->flush();
 }