public function load(ObjectManager $manager) { for ($i = 0; $i < 40; $i++) { $article = new Article(); $article->setTitle('News' . $i); $article->setContent('This is default content'); $article->setDatetime(new \DateTime('- ' . rand(1, 4) . ' day')); $commentA = new Comment(); $commentA->setAuthor('Author'); $commentA->setContent('Comment .... default'); $manager->persist($commentA); $article->addComment($commentA); $commentB = new Comment(); $commentB->setAuthor('Author' . $i); $commentB->setContent('Comment .... default'); $manager->persist($commentB); $article->addComment($commentB); $manager->persist($article); } $manager->flush(); }