我正在尝试根据参考键将两个表连接起来,但是出现以下错误
错误:[语义错误]第0行,'event_id = e.id'附近的col 85:错误:类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实体
/**
* @var int
*
* @ORM\Column(name="event_id", type="integer")
*/
private $eventId;
您应该了解该学说中的关联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;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句