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:
@@ -87,16 +87,11 @@ class Composant
|
||||
private ?Product $product = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Constructeur>
|
||||
* @var Collection<int, ComposantConstructeurLink>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Constructeur::class, inversedBy: 'composants')]
|
||||
#[ORM\JoinTable(
|
||||
name: '_ComposantConstructeurs',
|
||||
joinColumns: [new ORM\JoinColumn(name: 'A', referencedColumnName: 'id', onDelete: 'CASCADE')],
|
||||
inverseJoinColumns: [new ORM\InverseJoinColumn(name: 'B', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||
)]
|
||||
#[ORM\OneToMany(mappedBy: 'composant', targetEntity: ComposantConstructeurLink::class, cascade: ['remove'])]
|
||||
#[Groups(['composant:read'])]
|
||||
private Collection $constructeurs;
|
||||
private Collection $constructeurLinks;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Document>
|
||||
@@ -163,7 +158,7 @@ class Composant
|
||||
{
|
||||
$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->machineLinks = new ArrayCollection();
|
||||
@@ -260,43 +255,11 @@ class Composant
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Constructeur>
|
||||
* @return Collection<int, ComposantConstructeurLink>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -63,37 +63,37 @@ class Constructeur
|
||||
private DateTimeImmutable $updatedAt;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Machine>
|
||||
* @var Collection<int, MachineConstructeurLink>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Machine::class, mappedBy: 'constructeurs')]
|
||||
private Collection $machines;
|
||||
#[ORM\OneToMany(mappedBy: 'constructeur', targetEntity: MachineConstructeurLink::class, cascade: ['remove'])]
|
||||
private Collection $machineLinks;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Composant>
|
||||
* @var Collection<int, ComposantConstructeurLink>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Composant::class, mappedBy: 'constructeurs')]
|
||||
private Collection $composants;
|
||||
#[ORM\OneToMany(mappedBy: 'constructeur', targetEntity: ComposantConstructeurLink::class, cascade: ['remove'])]
|
||||
private Collection $composantLinks;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Piece>
|
||||
* @var Collection<int, PieceConstructeurLink>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Piece::class, mappedBy: 'constructeurs')]
|
||||
private Collection $pieces;
|
||||
#[ORM\OneToMany(mappedBy: 'constructeur', targetEntity: PieceConstructeurLink::class, cascade: ['remove'])]
|
||||
private Collection $pieceLinks;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Product>
|
||||
* @var Collection<int, ProductConstructeurLink>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Product::class, mappedBy: 'constructeurs')]
|
||||
private Collection $products;
|
||||
#[ORM\OneToMany(mappedBy: 'constructeur', targetEntity: ProductConstructeurLink::class, cascade: ['remove'])]
|
||||
private Collection $productLinks;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new DateTimeImmutable();
|
||||
$this->updatedAt = new DateTimeImmutable();
|
||||
$this->machines = new ArrayCollection();
|
||||
$this->composants = new ArrayCollection();
|
||||
$this->pieces = new ArrayCollection();
|
||||
$this->products = new ArrayCollection();
|
||||
$this->createdAt = new DateTimeImmutable();
|
||||
$this->updatedAt = new DateTimeImmutable();
|
||||
$this->machineLinks = new ArrayCollection();
|
||||
$this->composantLinks = new ArrayCollection();
|
||||
$this->pieceLinks = new ArrayCollection();
|
||||
$this->productLinks = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
|
||||
@@ -18,12 +18,14 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[ORM\Entity(repositoryClass: MachineRepository::class)]
|
||||
#[ORM\Table(name: 'machines')]
|
||||
#[ORM\HasLifecycleCallbacks]
|
||||
#[UniqueEntity(fields: ['reference'], message: 'Une machine avec cette référence existe déjà.')]
|
||||
#[ApiResource(
|
||||
description: 'Machines industrielles rattachées à un site. Chaque machine possède une structure hiérarchique de composants, pièces et produits, ainsi que des champs personnalisés et des documents.',
|
||||
operations: [
|
||||
@@ -59,15 +61,10 @@ class Machine
|
||||
private ?Site $site = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Constructeur>
|
||||
* @var Collection<int, MachineConstructeurLink>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Constructeur::class, inversedBy: 'machines')]
|
||||
#[ORM\JoinTable(
|
||||
name: '_MachineConstructeurs',
|
||||
joinColumns: [new ORM\JoinColumn(name: 'A', referencedColumnName: 'id', onDelete: 'CASCADE')],
|
||||
inverseJoinColumns: [new ORM\InverseJoinColumn(name: 'B', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||
)]
|
||||
private Collection $constructeurs;
|
||||
#[ORM\OneToMany(mappedBy: 'machine', targetEntity: MachineConstructeurLink::class, cascade: ['remove'])]
|
||||
private Collection $constructeurLinks;
|
||||
|
||||
/**
|
||||
* @var Collection<int, MachineComponentLink>
|
||||
@@ -125,7 +122,7 @@ class Machine
|
||||
$now = new DateTimeImmutable();
|
||||
$this->createdAt = $now;
|
||||
$this->updatedAt = $now;
|
||||
$this->constructeurs = new ArrayCollection();
|
||||
$this->constructeurLinks = new ArrayCollection();
|
||||
$this->componentLinks = new ArrayCollection();
|
||||
$this->pieceLinks = new ArrayCollection();
|
||||
$this->productLinks = new ArrayCollection();
|
||||
@@ -212,27 +209,11 @@ class Machine
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Constructeur>
|
||||
* @return Collection<int, MachineConstructeurLink>
|
||||
*/
|
||||
public function getConstructeurs(): Collection
|
||||
public function getConstructeurLinks(): Collection
|
||||
{
|
||||
return $this->constructeurs;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,16 +71,11 @@ class Product
|
||||
private ?ModelType $typeProduct = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Constructeur>
|
||||
* @var Collection<int, ProductConstructeurLink>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: Constructeur::class, inversedBy: 'products')]
|
||||
#[ORM\JoinTable(
|
||||
name: '_ProductConstructeurs',
|
||||
joinColumns: [new ORM\JoinColumn(name: 'A', referencedColumnName: 'id', onDelete: 'CASCADE')],
|
||||
inverseJoinColumns: [new ORM\InverseJoinColumn(name: 'B', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||
)]
|
||||
#[ORM\OneToMany(mappedBy: 'product', targetEntity: ProductConstructeurLink::class, cascade: ['remove'])]
|
||||
#[Groups(['product:read'])]
|
||||
private Collection $constructeurs;
|
||||
private Collection $constructeurLinks;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Document>
|
||||
@@ -138,7 +133,7 @@ class Product
|
||||
{
|
||||
$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->pieces = new ArrayCollection();
|
||||
@@ -196,43 +191,11 @@ class Product
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Constructeur>
|
||||
* @return Collection<int, ProductConstructeurLink>
|
||||
*/
|
||||
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