Add actors and their roles
This commit is contained in:
93
src/Entity/Actor.php
Normal file
93
src/Entity/Actor.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ActorRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ActorRepository::class)]
|
||||
class Actor
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $name = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?float $popularity = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, MovieRole>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: MovieRole::class, mappedBy: 'actor')]
|
||||
private Collection $movieRoles;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->movieRoles = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPopularity(): ?float
|
||||
{
|
||||
return $this->popularity;
|
||||
}
|
||||
|
||||
public function setPopularity(?float $popularity): static
|
||||
{
|
||||
$this->popularity = $popularity;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, MovieRole>
|
||||
*/
|
||||
public function getMovieRoles(): Collection
|
||||
{
|
||||
return $this->movieRoles;
|
||||
}
|
||||
|
||||
public function addMovieRole(MovieRole $movieRole): static
|
||||
{
|
||||
if (!$this->movieRoles->contains($movieRole)) {
|
||||
$this->movieRoles->add($movieRole);
|
||||
$movieRole->setActor($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeMovieRole(MovieRole $movieRole): static
|
||||
{
|
||||
if ($this->movieRoles->removeElement($movieRole)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($movieRole->getActor() === $this) {
|
||||
$movieRole->setActor(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user