create offerings and its migration

This commit is contained in:
Jannis Portmann 2021-04-24 17:36:38 +02:00
parent f3ad0e4638
commit 307954d46f
4 changed files with 223 additions and 0 deletions

View file

@ -3,6 +3,8 @@
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
@ -47,6 +49,16 @@ class User implements UserInterface
*/
private $username;
/**
* @ORM\OneToMany(targetEntity=Offering::class, mappedBy="byUser", orphanRemoval=true)
*/
private $offerings;
public function __construct()
{
$this->offerings = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
@ -146,4 +158,34 @@ class User implements UserInterface
return $this;
}
/**
* @return Collection|Offering[]
*/
public function getOfferings(): Collection
{
return $this->offerings;
}
public function addOffering(Offering $offering): self
{
if (!$this->offerings->contains($offering)) {
$this->offerings[] = $offering;
$offering->setByUser($this);
}
return $this;
}
public function removeOffering(Offering $offering): self
{
if ($this->offerings->removeElement($offering)) {
// set the owning side to null (unless already changed)
if ($offering->getByUser() === $this) {
$offering->setByUser(null);
}
}
return $this;
}
}