无法使用symfony doctrine将非关联表或非关联表连接在一起

时间:2016-12-16 14:00:49

标签: symfony doctrine

我尝试根据引用键加入这两个表,但收到以下错误

错误: [语义错误]第0行,第85行附近' event_id = e.id':错误:类AppBundle \ Entity \ EventLocation没有名为event_id的字段或关联

以下是查询

$qb = $this
        ->createQueryBuilder('e')
        ->select('e')            
        ->innerJoin('AppBundle:EventLocation', 'el', 'WITH', 'el.event_id = e.id')            
        ->where('e.event_id = :event_id')    
        ->setParameter('event_id', $eventId);

EventLocation Entity

    /**
     * @var int
     *
     * @ORM\Column(name="event_id", type="integer")
    */
private $eventId;

1 个答案:

答案 0 :(得分:1)

Yous应该在学说http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html

中看一下关联

要加入学说中的实体,您需要一个协会

<?php
use Doctrine\ORM\Mapping AS ORM;

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

    /**
     * @ORM\OneToOne(targetEntity="EventLocation", mappedBy="event")
     */
    private $eventLocation;
}

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

    /**
     * @ORM\JoinColumn(name="event_id", referencedColumnName="id", unique=true)
     * @ORM\OneToOne(targetEntity="Event", inversedBy="eventLocation")
     */
    private $event;
}