added Blog entity

This commit is contained in:
2021-05-30 18:18:30 +02:00
parent aeaaae7bf5
commit 32e8e11882
5 changed files with 346 additions and 14 deletions

View File

@@ -3,6 +3,8 @@
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
@@ -59,6 +61,16 @@ class User implements UserInterface
*/
private $lastLoginAt;
/**
* @ORM\OneToMany(targetEntity=Blog::class, mappedBy="author")
*/
private $blogs;
public function __construct()
{
$this->blogs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
@@ -194,4 +206,34 @@ class User implements UserInterface
return $this;
}
/**
* @return Collection|Blog[]
*/
public function getBlogs(): Collection
{
return $this->blogs;
}
public function addBlog(Blog $blog): self
{
if (!$this->blogs->contains($blog)) {
$this->blogs[] = $blog;
$blog->setAuthor($this);
}
return $this;
}
public function removeBlog(Blog $blog): self
{
if ($this->blogs->removeElement($blog)) {
// set the owning side to null (unless already changed)
if ($blog->getAuthor() === $this) {
$blog->setAuthor(null);
}
}
return $this;
}
}