Added files to books.
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\BookRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: BookRepository::class)]
|
||||
@@ -37,6 +39,14 @@ class Book
|
||||
#[ORM\Column(type: 'string', length: 255, nullable: true)]
|
||||
private $subtitle;
|
||||
|
||||
#[ORM\OneToMany(mappedBy: 'book', targetEntity: File::class, orphanRemoval: true)]
|
||||
private $files;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->files = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@@ -137,4 +147,34 @@ class Book
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, File>
|
||||
*/
|
||||
public function getFiles(): Collection
|
||||
{
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
public function addFile(File $file): self
|
||||
{
|
||||
if (!$this->files->contains($file)) {
|
||||
$this->files[] = $file;
|
||||
$file->setBook($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeFile(File $file): self
|
||||
{
|
||||
if ($this->files->removeElement($file)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($file->getBook() === $this) {
|
||||
$file->setBook(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user