relation ManyToMany done
This commit is contained in:
5
doctrine_migration_20241121090449.sql
Normal file
5
doctrine_migration_20241121090449.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
-- Doctrine Migration File Generated on 2024-11-21 09:04:49
|
||||
|
||||
-- Version DoctrineMigrations\Version20241121085948
|
||||
ALTER TABLE sortie ADD CONSTRAINT FK_3C3FD3F2D936B2FA FOREIGN KEY (organisateur_id) REFERENCES participant (id_participant);
|
||||
CREATE INDEX IDX_3C3FD3F2D936B2FA ON sortie (organisateur_id);
|
||||
@@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20241120131557 extends AbstractMigration
|
||||
final class Version20241121085948 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
@@ -20,12 +20,14 @@ final class Version20241120131557 extends AbstractMigration
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE participant ADD pending TINYINT(1) NOT NULL');
|
||||
$this->addSql('ALTER TABLE sortie ADD CONSTRAINT FK_3C3FD3F2D936B2FA FOREIGN KEY (organisateur_id) REFERENCES participant (id_participant)');
|
||||
$this->addSql('CREATE INDEX IDX_3C3FD3F2D936B2FA ON sortie (organisateur_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE participant DROP pending');
|
||||
$this->addSql('ALTER TABLE sortie DROP FOREIGN KEY FK_3C3FD3F2D936B2FA');
|
||||
$this->addSql('DROP INDEX IDX_3C3FD3F2D936B2FA ON sortie');
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\SortieRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
@@ -37,9 +39,9 @@ class Sortie
|
||||
#[ORM\JoinColumn(name: 'site_id', referencedColumnName: 'id_site', nullable: false)]
|
||||
private ?Site $site = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Participant::class, inversedBy: 'sorties')]
|
||||
#[ORM\JoinColumn(name: 'participant_id', referencedColumnName: 'id_participant', nullable: false)]
|
||||
private ?Participant $participant = null;
|
||||
#[ORM\ManyToOne(targetEntity: Participant::class, inversedBy: 'sortiesOrganisateur')]
|
||||
#[ORM\JoinColumn(name: 'organisateur_id', referencedColumnName: 'id_participant', nullable: false)]
|
||||
private ?Participant $organisateur = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Lieu::class, inversedBy: 'sorties')]
|
||||
#[ORM\JoinColumn(name: 'lieu_id', referencedColumnName: 'id_lieu', nullable: false)]
|
||||
@@ -49,6 +51,17 @@ class Sortie
|
||||
#[ORM\JoinColumn(name: 'etat_id', referencedColumnName: 'id_etat', nullable: false)]
|
||||
private ?Etat $etat = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Participant>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Participant::class, mappedBy: 'sortiesParticipants')]
|
||||
private Collection $participants;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->participants = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getIdSortie(): ?string
|
||||
{
|
||||
return $this->idSortie;
|
||||
@@ -138,14 +151,14 @@ class Sortie
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getParticipant(): ?Participant
|
||||
public function getOrganisateur(): ?Participant
|
||||
{
|
||||
return $this->participant;
|
||||
return $this->organisateur;
|
||||
}
|
||||
|
||||
public function setParticipant(?Participant $participant): self
|
||||
public function setOrganisateur(?Participant $organisateur): self
|
||||
{
|
||||
$this->participant = $participant;
|
||||
$this->organisateur = $organisateur;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -173,4 +186,28 @@ class Sortie
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Participant>
|
||||
*/
|
||||
public function getParticipants(): Collection
|
||||
{
|
||||
return $this->participants;
|
||||
}
|
||||
|
||||
public function addParticipant(Participant $participant): static
|
||||
{
|
||||
if (!$this->participants->contains($participant)) {
|
||||
$this->participants->add($participant);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeParticipant(Participant $participant): static
|
||||
{
|
||||
$this->participants->removeElement($participant);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user