Skip to content

Commit 0db7504

Browse files
committed
Use Post::addComment to associate comment with post
1 parent 1e0b3d6 commit 0db7504

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/AppBundle/Controller/BlogController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public function commentNewAction(Request $request, Post $post)
9494
{
9595
$comment = new Comment();
9696
$comment->setAuthor($this->getUser());
97-
$comment->setPost($post);
97+
98+
$post->addComment($comment);
9899

99100
$form = $this->createForm(CommentType::class, $comment);
100101

src/AppBundle/DataFixtures/ORM/PostFixtures.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ public function load(ObjectManager $manager)
6666
$comment->setAuthor($this->getReference('john-user'));
6767
$comment->setPublishedAt(new \DateTime('now + '.($i + $j).'seconds'));
6868
$comment->setContent($this->getRandomCommentContent());
69-
$comment->setPost($post);
7069

71-
$manager->persist($comment);
7270
$post->addComment($comment);
71+
72+
$manager->persist($comment);
7373
}
7474

7575
$manager->persist($post);

0 commit comments

Comments
 (0)