Symfony4-未定义索引:实体连接时

时间:2018-10-11 16:57:38

标签: symfony doctrine symfony4

我得到

  

未定义索引:订单

即使我使用this documentation可以判断出

错误,但我所做的一切都正确。有什么想法吗?

OrdersRepository

public function findByDateAndEmployee(\DateTime $date, int $employeeId)
{
    return $this->createQueryBuilder('o')
        ->select('o')
        ->join('o.employees' ,'e')
        ->where('e.id = :id')
        ->setParameter('id',$employeeId)
    ->getQuery()->getSql();
}

订单实体

class Orders
{
  ...
    /**
     * One Order has Many Employees.
     * @ORM\OneToMany(targetEntity="Employee", mappedBy="order", cascade={"persist", "remove"}, orphanRemoval=TRUE)
     */
     private $employees;

我知道如果我在“ mappedBy”中更改了变量,它将错误消息更改为任何变量名称,但是,当您在“ order”下面看到时,应该是mappedBy变量(至少,我认为)。

OrderEmployees实体

class OrderEmployees
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="integer")
     */
    private $orderId;

    /**
     * @ORM\Column(type="smallint")
     */
    private $employeeId;

    /**
     * @ORM\ManyToOne(targetEntity="Orders", inversedBy="employees")
     * @ORM\JoinColumn(name="order_id", referencedColumnName="id")
     */
    private $order;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getOrderId(): ?int
    {
        return $this->orderId;
    }

    public function setOrderId(int $orderId): self
    {
        $this->orderId = $orderId;

        return $this;
    }

    public function getEmployeeId(): ?int
    {
       return $this->employeeId;
    }

    public function setEmployeeId(int $employeeId): self
    {
       $this->employeeId = $employeeId;

       return $this;
    }

    public function getOrder(): Orders
    {
        return $this->order;
    }

    public function setOrder(Orders $order): self
    {
        $this->order = $order;

        return $this;
    }
}

1 个答案:

答案 0 :(得分:2)

在您的订单实体中将targetEntity="Employee"更改为targetEntity="OrderEmployees"应该会有所帮助。

来自docs

  

targetEntity:所引用目标实体的FQCN。可以是   如果两个类都在同一个命名空间中,则为不合格的类名。