Я сопоставляю один со многими отношениями. 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
Кемеровские программисты php общаются здесь
1746262370
Anonymous
Я сопоставляю один со многими отношениями. 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: [b]Unrecognized field: App\Entity\Product: :$product (500 Internal Server Error)[/b]
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;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79604495/symfony-orm-mapping-any-expert-please-help-me-or-i-will-hit-my-head-on-wall[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия