问题描述
我正在尝试使用联接查询来进行主义查询。 我已经做了以下事情:
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;
CategorieParent实体
/**
* @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;
这应该是最好的选择,因为它将为您提供数据库和实体之间的正确映射。
否则,您只能disable notice reporting:
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
?>