<?php
namespace App\Entity;
use App\Repository\PreferenceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=PreferenceRepository::class)
*/
class Preference
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\OneToMany(targetEntity=BlogPost::class, mappedBy="preference")
*/
private $blogPosts;
public function __construct()
{
$this->blogPosts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
/**
* @return Collection<int, BlogPost>
*/
public function getBlogPosts(): Collection
{
return $this->blogPosts;
}
public function addBlogPost(BlogPost $blogPost): self
{
if (!$this->blogPosts->contains($blogPost)) {
$this->blogPosts[] = $blogPost;
$blogPost->setPreference($this);
}
return $this;
}
public function removeBlogPost(BlogPost $blogPost): self
{
if ($this->blogPosts->removeElement($blogPost)) {
// set the owning side to null (unless already changed)
if ($blogPost->getPreference() === $this) {
$blogPost->setPreference(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->getTitle() ?? '';
}
}