public function load(ObjectManager $manager) { $recipe = new Recipe(); $recipe->setName('Pea Soup'); $recipe->setCreatedAt(new \DateTime()); $recipe->addIngredient($this->getReference('ingredient-green-lentils')); $recipe->addIngredient($this->getReference('ingredient-potato')); $recipe->addIngredient($this->getReference('ingredient-carrot')); $recipe->addIngredient($this->getReference('ingredient-celeriac')); $recipe->addIngredient($this->getReference('ingredient-leek')); $manager->persist($recipe); // $recipeNames = [ // 'Sweet Potato Mash', // 'Bread', // 'Saoto Soup', // 'Gumbo', // 'Banana Bread', // 'Paella', // 'Pancakes', // 'Apple Pie', // 'Mojito', // 'Roti', // 'jambalaya', // 'Hutspot' // ]; // // foreach ($recipeNames as $recipeName) { // $recipe = new Recipe(); // $recipe->setName($recipeName); // $recipe->setCreatedAt(new \DateTime()); // $manager->persist($recipe); // } $manager->flush(); }
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(); }