[英]Symfony Doctrine Undefined Index
我正在嘗試使用連接查詢來制作 Doctrine 查詢。 我做了以下事情:
public function getCategoriesFromCategorieParentAndConstructeur(): ?Array
{
return $this->createQueryBuilder('c')
->leftJoin('c.categorie_parent_id', 'cp' )
->getQuery()
->getResult();
}
但是當我嘗試顯示結果時出現以下錯誤:
注意:未定義索引:類別
我不知道你為什么能告訴我更多?
這是我的 2 實體:類別實體
/**
* @ORM\Entity(repositoryClass="App\Repository\CategorieRepository")
*/
class Categorie
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $categorie_intitule;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\CategorieParent", inversedBy="categorie_id")
*/
private $categorie_parent_id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="categories")
*/
private $created_by;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Produit", mappedBy="categorie_id", orphanRemoval=true)
*/
private $produits;
類別父實體
/**
* @ORM\OneToMany(targetEntity="App\Entity\Categorie", mappedBy="categorie_parent_id", cascade={"remove"})
*/
private $categorie_id;
public function __construct()
{
$this->categorie_id = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCategorieIntitule(): ?string
{
return $this->categorie_intitule;
}
public function setCategorieIntitule(string $categorie_intitule): self
{
$this->categorie_intitule = $categorie_intitule;
return $this;
}
謝謝你
您可以按照此通知告訴您的內容並在您的用戶實體中定義您的變量$categories
,這可能是:
/**
* @ORM\OneToMany(targetEntity=App\Entity\Categorie, mappedBy="created_by")
*/
private $categories;
這應該是最好的選擇,因為它將為您提供數據庫和實體之間的正確映射。
否則,您可以禁用通知報告:
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.