Add species fixture
This commit is contained in:
@@ -31,6 +31,9 @@ class Post
|
||||
|
||||
#[ORM\Column(type: Types::TEXT)]
|
||||
private ?string $commentary = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'posts')]
|
||||
private ?Species $species = null;
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@@ -107,4 +110,16 @@ class Post
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSpecies(): ?Species
|
||||
{
|
||||
return $this->species;
|
||||
}
|
||||
|
||||
public function setSpecies(?Species $species): static
|
||||
{
|
||||
$this->species = $species;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user