refactor(constructeur) : replace ManyToMany with OneToMany to ConstructeurLink entities
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -86,16 +86,11 @@ class Piece
|
||||
private ?Product $product = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Constructeur>
|
||||
* @var Collection<int, PieceConstructeurLink>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Constructeur::class, inversedBy: 'pieces')]
|
||||
#[ORM\JoinTable(
|
||||
name: '_PieceConstructeurs',
|
||||
joinColumns: [new ORM\JoinColumn(name: 'A', referencedColumnName: 'id', onDelete: 'CASCADE')],
|
||||
inverseJoinColumns: [new ORM\InverseJoinColumn(name: 'B', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||
)]
|
||||
#[ORM\OneToMany(mappedBy: 'piece', targetEntity: PieceConstructeurLink::class, cascade: ['remove'])]
|
||||
#[Groups(['piece:read'])]
|
||||
private Collection $constructeurs;
|
||||
private Collection $constructeurLinks;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Document>
|
||||
@@ -151,7 +146,7 @@ class Piece
|
||||
{
|
||||
$this->createdAt = new DateTimeImmutable();
|
||||
$this->updatedAt = new DateTimeImmutable();
|
||||
$this->constructeurs = new ArrayCollection();
|
||||
$this->constructeurLinks = new ArrayCollection();
|
||||
$this->documents = new ArrayCollection();
|
||||
$this->customFieldValues = new ArrayCollection();
|
||||
$this->products = new ArrayCollection();
|
||||
@@ -260,43 +255,11 @@ class Piece
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Constructeur>
|
||||
* @return Collection<int, PieceConstructeurLink>
|
||||
*/
|
||||
public function getConstructeurs(): Collection
|
||||
public function getConstructeurLinks(): Collection
|
||||
{
|
||||
return $this->constructeurs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param iterable<Constructeur> $constructeurs
|
||||
*/
|
||||
public function setConstructeurs(iterable $constructeurs): static
|
||||
{
|
||||
$this->constructeurs = new ArrayCollection();
|
||||
|
||||
foreach ($constructeurs as $constructeur) {
|
||||
if ($constructeur instanceof Constructeur && !$this->constructeurs->contains($constructeur)) {
|
||||
$this->constructeurs->add($constructeur);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addConstructeur(Constructeur $constructeur): static
|
||||
{
|
||||
if (!$this->constructeurs->contains($constructeur)) {
|
||||
$this->constructeurs->add($constructeur);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeConstructeur(Constructeur $constructeur): static
|
||||
{
|
||||
$this->constructeurs->removeElement($constructeur);
|
||||
|
||||
return $this;
|
||||
return $this->constructeurLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user