relation ManyToMany done

This commit is contained in:
Olivier PARPAILLON
2024-11-21 10:06:47 +01:00
parent 182d1867c5
commit 3b1511d76f
4 changed files with 104 additions and 23 deletions

View File

@@ -60,12 +60,22 @@ class Participant implements UserInterface, PasswordAuthenticatedUserInterface
/**
* @var Collection<int, Sortie>
*/
#[ORM\OneToMany(targetEntity: Sortie::class, mappedBy: 'participant')]
private Collection $sorties;
#[ORM\OneToMany(targetEntity: Sortie::class, mappedBy: 'organisateur')]
private Collection $sortiesOrganisateur;
/**
* @var Collection<int, Sortie>
*/
#[ORM\ManyToMany(targetEntity: Sortie::class, inversedBy: 'participants')]
#[ORM\JoinTable(name: 'participant_sortie')]
#[ORM\JoinColumn(name: 'participant_id', referencedColumnName: 'id_participant')]
#[ORM\InverseJoinColumn(name: 'sortie_id', referencedColumnName: 'id_sortie')]
private Collection $sortiesParticipants;
public function __construct()
{
$this->sorties = new ArrayCollection();
$this->sortiesOrganisateur = new ArrayCollection();
$this->sortiesParticipants = new ArrayCollection();
}
public function getIdParticipant(): ?string
@@ -239,27 +249,27 @@ class Participant implements UserInterface, PasswordAuthenticatedUserInterface
/**
* @return Collection<int, Sortie>
*/
public function getSorties(): Collection
public function getSortiesOrganisateur(): Collection
{
return $this->sorties;
return $this->sortiesOrganisateur;
}
public function addSortie(Sortie $sortie): self
public function addSortieOrganisateur(Sortie $sortie): self
{
if (!$this->sorties->contains($sortie)) {
$this->sorties->add($sortie);
$sortie->setParticipant($this);
if (!$this->sortiesOrganisateur->contains($sortie)) {
$this->sortiesOrganisateur->add($sortie);
$sortie->setOrganisateur($this);
}
return $this;
}
public function removeSortie(Sortie $sortie): self
public function removeSortieOrganisateur(Sortie $sortie): self
{
if ($this->sorties->removeElement($sortie)) {
if ($this->sortiesOrganisateur->removeElement($sortie)) {
// Set the owning side to null (unless already changed)
if ($sortie->getParticipant() === $this) {
$sortie->setParticipant(null);
if ($sortie->getOrganisateur() === $this) {
$sortie->setOrganisateur(null);
}
}
@@ -275,4 +285,31 @@ class Participant implements UserInterface, PasswordAuthenticatedUserInterface
{
$this->fileName = $fileName;
}
/**
* @return Collection<int, Sortie>
*/
public function getSortiesParticipants(): Collection
{
return $this->sortiesParticipants;
}
public function addSortiesParticipant(Sortie $sortiesParticipant): static
{
if (!$this->sortiesParticipants->contains($sortiesParticipant)) {
$this->sortiesParticipants->add($sortiesParticipant);
$sortiesParticipant->addParticipant($this);
}
return $this;
}
public function removeSortiesParticipant(Sortie $sortiesParticipant): static
{
if ($this->sortiesParticipants->removeElement($sortiesParticipant)) {
$sortiesParticipant->removeParticipant($this);
}
return $this;
}
}