groupes de rendu api contre la dépendance circulaire dans groupeofproducts

This commit is contained in:
Tykayn 2025-02-17 17:57:37 +01:00 committed by tykayn
parent c1b2c97350
commit 19cdb12d28
2 changed files with 8 additions and 3 deletions

View file

@ -10,6 +10,8 @@ use Doctrine\ORM\Mapping as ORM;
use \App\Entity\GroupOfProducts;
use \App\Entity\Product;
use \App\Entity\Selling;
use ApiPlatform\Metadata\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
#[ApiResource(paginationEnabled: false)]
#[ORM\Entity(repositoryClass: GroupOfProductsRepository::class)]
@ -21,12 +23,14 @@ class GroupOfProducts
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['default'])]
private ?string $name = null;
/**
* @var Collection<int, Product>
*/
#[ORM\ManyToMany(targetEntity: Product::class, inversedBy: 'groupOfProducts')]
#[Groups(['default'])]
private Collection $products;
/**
@ -75,7 +79,8 @@ class GroupOfProducts
return $productsDTO;
}
public function getProducts(): ?object
#[Groups(['default'])]
public function getProducts(): Collection
{
return $this->products;
}

View file

@ -24,11 +24,11 @@ class Product
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['default', 'relation'])]
#[Groups(['default'])]
private ?string $name = null;
#[ORM\Column]
#[Groups(['default', 'relation'])]
#[Groups(['default'])]
private ?float $price = null;
#[ORM\Column]