private function populate() { $repo = $this->em->getRepository(self::ARTICLE); $commentRepo = $this->em->getRepository(self::COMMENT); $food = new Article(); $food->setTitle('Food'); $food->setContent('about food'); $food->setAuthor('John Doe'); $food->setViews(99); $goodFood = new Comment(); $goodFood->setArticle($food); $goodFood->setMessage('food is good'); $goodFood->setSubject('good'); $badFood = new Comment(); $badFood->setArticle($food); $badFood->setMessage('food is bad'); $badFood->setSubject('bad'); $this->em->persist($food); $this->em->persist($goodFood); $this->em->persist($badFood); $this->em->flush(); $this->em->clear(); $this->translatableListener->setTranslatableLocale('lt_lt'); $food = $repo->find(1); $food->setTitle('Maistas'); $food->setContent('apie maista'); $food->setViews(999); $goodFood = $commentRepo->find(1); $goodFood->setArticle($food); $goodFood->setMessage('maistas yra geras'); $goodFood->setSubject('geras'); $badFood = $commentRepo->find(2); $badFood->setArticle($food); $badFood->setMessage('maistas yra blogas'); $badFood->setSubject('blogas'); $this->em->persist($food); $this->em->persist($goodFood); $this->em->persist($badFood); $this->em->flush(); $this->em->clear(); }
private function populate() { $article = new Article(); $article->setTitle('title in en'); $article->setContent('content in en'); $comment1 = new Comment(); $comment1->setSubject('subject1 in en'); $comment1->setMessage('message1 in en'); $comment2 = new Comment(); $comment2->setSubject('subject2 in en'); $comment2->setMessage('message2 in en'); $article->addComment($comment1); $article->addComment($comment2); $this->em->persist($article); $this->em->persist($comment1); $this->em->persist($comment2); $this->em->flush(); $this->articleId = $article->getId(); $this->em->clear(); }
public function addComment(Comment $comment) { $comment->setArticle($this); $this->comments[] = $comment; }