Adding relations between objects, missing followed relation on Porfils

master
Corentin RICHARD 11 months ago
parent cc33e821ee
commit 403da7e9ec

@ -18,6 +18,14 @@ class Commentary
#[ORM\Column(length: 255, nullable: true)]
private ?string $text = null;
#[ORM\ManyToOne(inversedBy: 'commentaries')]
#[ORM\JoinColumn(nullable: false)]
private ?Post $post = null;
#[ORM\ManyToOne(inversedBy: 'commentaries')]
#[ORM\JoinColumn(nullable: false)]
private ?Profil $profil = null;
public function getId(): ?int
{
return $this->id;
@ -34,4 +42,28 @@ class Commentary
return $this;
}
public function getPost(): ?Post
{
return $this->post;
}
public function setPost(?Post $post): static
{
$this->post = $post;
return $this;
}
public function getProfil(): ?Profil
{
return $this->profil;
}
public function setProfil(?Profil $profil): static
{
$this->profil = $profil;
return $this;
}
}

@ -4,6 +4,8 @@ namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\PostRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PostRepository::class)]
@ -30,6 +32,28 @@ class Post
#[ORM\Column]
private ?int $downVote = null;
#[ORM\ManyToOne(inversedBy: 'posts')]
#[ORM\JoinColumn(nullable: false)]
private ?Profil $profil = null;
/**
* @var Collection<int, Commentary>
*/
#[ORM\OneToMany(targetEntity: Commentary::class, mappedBy: 'post')]
private Collection $commentaries;
/**
* @var Collection<int, Tags>
*/
#[ORM\ManyToMany(targetEntity: Tags::class, inversedBy: 'posts')]
private Collection $tags;
public function __construct()
{
$this->commentaries = new ArrayCollection();
$this->tags = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
@ -94,4 +118,70 @@ class Post
return $this;
}
public function getProfil(): ?Profil
{
return $this->profil;
}
public function setProfil(?Profil $profil): static
{
$this->profil = $profil;
return $this;
}
/**
* @return Collection<int, Commentary>
*/
public function getCommentaries(): Collection
{
return $this->commentaries;
}
public function addCommentary(Commentary $commentary): static
{
if (!$this->commentaries->contains($commentary)) {
$this->commentaries->add($commentary);
$commentary->setPost($this);
}
return $this;
}
public function removeCommentary(Commentary $commentary): static
{
if ($this->commentaries->removeElement($commentary)) {
// set the owning side to null (unless already changed)
if ($commentary->getPost() === $this) {
$commentary->setPost(null);
}
}
return $this;
}
/**
* @return Collection<int, Tags>
*/
public function getTags(): Collection
{
return $this->tags;
}
public function addTag(Tags $tag): static
{
if (!$this->tags->contains($tag)) {
$this->tags->add($tag);
}
return $this;
}
public function removeTag(Tags $tag): static
{
$this->tags->removeElement($tag);
return $this;
}
}

@ -4,6 +4,8 @@ namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\ProfilRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ProfilRepository::class)]
@ -24,6 +26,31 @@ class Profil
#[ORM\Column(length: 255, nullable: true)]
private ?string $password = null;
/**
* @var Collection<int, Post>
*/
#[ORM\OneToMany(targetEntity: Post::class, mappedBy: 'profil')]
private Collection $posts;
/**
* @var Collection<int, Commentary>
*/
#[ORM\OneToMany(targetEntity: Commentary::class, mappedBy: 'profil')]
private Collection $commentaries;
/**
* @var Collection<int, self>
*/
#[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'followers')]
private Collection $followers;
public function __construct()
{
$this->posts = new ArrayCollection();
$this->commentaries = new ArrayCollection();
$this->followers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
@ -64,4 +91,88 @@ class Profil
return $this;
}
/**
* @return Collection<int, Post>
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): static
{
if (!$this->posts->contains($post)) {
$this->posts->add($post);
$post->setProfil($this);
}
return $this;
}
public function removePost(Post $post): static
{
if ($this->posts->removeElement($post)) {
// set the owning side to null (unless already changed)
if ($post->getProfil() === $this) {
$post->setProfil(null);
}
}
return $this;
}
/**
* @return Collection<int, Commentary>
*/
public function getCommentaries(): Collection
{
return $this->commentaries;
}
public function addCommentary(Commentary $commentary): static
{
if (!$this->commentaries->contains($commentary)) {
$this->commentaries->add($commentary);
$commentary->setProfil($this);
}
return $this;
}
public function removeCommentary(Commentary $commentary): static
{
if ($this->commentaries->removeElement($commentary)) {
// set the owning side to null (unless already changed)
if ($commentary->getProfil() === $this) {
$commentary->setProfil(null);
}
}
return $this;
}
/**
* @return Collection<int, self>
*/
public function getFollowers(): Collection
{
return $this->followers;
}
public function addFollower(self $follower): static
{
if (!$this->followers->contains($follower)) {
$this->followers->add($follower);
}
return $this;
}
public function removeFollower(self $follower): static
{
$this->followers->removeElement($follower);
return $this;
}
}

@ -4,6 +4,8 @@ namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\TagsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: TagsRepository::class)]
@ -21,6 +23,17 @@ class Tags
#[ORM\Column(length: 255, nullable: true)]
private ?string $color = null;
/**
* @var Collection<int, Post>
*/
#[ORM\ManyToMany(targetEntity: Post::class, mappedBy: 'tags')]
private Collection $posts;
public function __construct()
{
$this->posts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
@ -49,4 +62,31 @@ class Tags
return $this;
}
/**
* @return Collection<int, Post>
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): static
{
if (!$this->posts->contains($post)) {
$this->posts->add($post);
$post->addTag($this);
}
return $this;
}
public function removePost(Post $post): static
{
if ($this->posts->removeElement($post)) {
$post->removeTag($this);
}
return $this;
}
}

Loading…
Cancel
Save