Я сопоставляю один со многими отношениями. I have a product entity under which there will be multiple features but I am getting this error and now I am frustrated here
error: Unrecognized field: App\Entity\Product: :$product (500 Internal Server Error)
this error is raising while calling the API
below is the relevant files contents
calling file
/**
* @Route("/api/products/{id}/features", name="Features_list", methods={"GET"})
*/
public function featuresList(int $id, EntityManagerInterface $em): JsonResponse
{
$product = $em->getRepository(Product::class)->find($id);
if (!$product) {
return new JsonResponse(['message' => 'No product found'], 404);
}
// print_r($product);exit();
$features = $em->getRepository(Feature::class)->findBy([
'product' => $product,
'deleted' => 0
]);
if (!$features) {
return new JsonResponse(['message' => 'No features found'], 404);
}
< /code>
feature.php
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product", inversedBy="features")
* @ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false,
onDelete="CASCADE")
*/
private $product;
< /code>
product.php
/**
* @ORM\OneToMany(targetEntity="App\Entity\Feature", mappedBy="product", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $features;
/**
* @return Collection|Feature[]
*/
public function getFeatures(): Collection
{
return $this->features;
}
public function addFeature(Feature $feature): self
{
if (!$this->features->contains($feature)) {
$this->features[] = $feature;
$feature->setProduct($this);
}
return $this;
}
public function removeFeature(Feature $feature): self
{
if ($this->features->removeElement($feature)) {
if ($feature->getProduct() === $this) {
$feature->setProduct(null);
}
}
return $this;
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... ad-on-wall
Symfony Orm Maping любого эксперта, пожалуйста, помогите мне, или я порадусь головой на стене ⇐ Php
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение