← Back
Editing: UserAddress.php
<?php namespace App\Entity; use App\Repository\UserAddressRepository; use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping\UniqueConstraint; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; #[ORM\Entity(repositoryClass: UserAddressRepository::class)] #[UniqueConstraint(fields: ['user', 'address', 'startDate', 'endDate'])] #[UniqueEntity(['user', 'address', 'startDate', 'endDate'])] class UserAddress { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: 'integer')] private ?int $id = null; #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'userAddresses')] #[ORM\JoinColumn(nullable: false, onDelete: 'cascade')] private ?User $user = null; #[ORM\ManyToOne(targetEntity: Adresse::class, inversedBy: 'userAddresses')] #[ORM\JoinColumn(nullable: false, onDelete: 'cascade')] private ?Adresse $address = null; #[ORM\Column(type: 'date', nullable: true)] private ?\DateTimeInterface $startDate = null; #[ORM\Column(type: 'date', nullable: true)] private ?\DateTimeInterface $endDate = null; #[ORM\Column(type: 'datetime_immutable')] private \DateTimeImmutable $createdAt; public function __construct() { $this->createdAt = new \DateTimeImmutable(); } public function __toString() { return sprintf('%s - %s', $this->getUser(), $this->getAddress()->getAddressString()); } public function getId(): ?int { return $this->id; } public function getUser(): ?User { return $this->user; } public function setUser(?User $user): self { $this->user = $user; return $this; } public function getStartDate(): ?\DateTimeInterface { return $this->startDate; } public function setStartDate(?\DateTimeInterface $startDate): self { $this->startDate = $startDate; return $this; } public function getEndDate(): ?\DateTimeInterface { return $this->endDate; } public function setEndDate(?\DateTimeInterface $endDate): self { $this->endDate = $endDate; return $this; } public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; } public function setCreatedAt(\DateTimeImmutable $createdAt): self { $this->createdAt = $createdAt; return $this; } public function getAddress(): ?Adresse { return $this->address; } public function setAddress(?Adresse $address): self { $this->address = $address; return $this; } }
Save File
Cancel