Symfony主义未定义索引

问题描述

我正在尝试使用联接查询来进行主义查询。 我已经做了以下事情:

    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); 
?>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...