Add species fixture

This commit is contained in:
2024-05-22 17:16:38 +02:00
parent cfb53dad52
commit d4cc71946d
7 changed files with 342 additions and 1 deletions

View File

@@ -3,6 +3,8 @@
namespace App\Entity;
use App\Repository\SpeciesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: SpeciesRepository::class)]
@@ -22,6 +24,17 @@ class Species
#[ORM\Column(length: 255)]
private ?string $region = null;
/**
* @var Collection<int, Post>
*/
#[ORM\OneToMany(targetEntity: Post::class, mappedBy: 'species')]
private Collection $posts;
public function __construct()
{
$this->posts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
@@ -62,4 +75,34 @@ class Species
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->setSpecies($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->getSpecies() === $this) {
$post->setSpecies(null);
}
}
return $this;
}
}