added Comment entity

This commit is contained in:
2021-05-30 18:24:32 +02:00
parent 32e8e11882
commit 55dca7b8ce
7 changed files with 359 additions and 11 deletions

View File

@@ -66,9 +66,15 @@ class User implements UserInterface
*/
private $blogs;
/**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="author")
*/
private $comments;
public function __construct()
{
$this->blogs = new ArrayCollection();
$this->comments = new ArrayCollection();
}
public function getId(): ?int
@@ -236,4 +242,34 @@ class User implements UserInterface
return $this;
}
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comment $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setAuthor($this);
}
return $this;
}
public function removeComment(Comment $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getAuthor() === $this) {
$comment->setAuthor(null);
}
}
return $this;
}
}