我遇到教条查询生成器的问题,给我一个[语义错误]我正在尝试构建的查询是这样的: -
$query = $this->_em->createQueryBuilder()
->select('r, m')
->from('Ajfit\Entity\TicketReply', 'r')
->join('r.mailFk', 'm')
->where('r.ticketFk = :ticket')
->orderBy('m.dt', 'desc')
->setParameter('ticket', $ticket)
->getQuery();
$paginator = new Paginator($query);
return $paginator->getIterator(); //////////blows up here!
引发的错误是: -
[Semantical Error] line 0, col 64 near 'm WHERE r.ticketFk': Error: Class Ajfit\Entity\TicketReply has no association named mailFk
错误所指的实体是: -
命名空间Ajfit \ Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Persistence\PersistentObject;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Ajfit\Entity\TicketReply
*
* @ORM\Table(name="ticket_reply")
* @ORM\Entity(repositoryClass="Ajfit\Repository\TicketReply")
* @ORM\HasLifecycleCallbacks
*/
class TicketReply extends \Doctrine\Common\Persistence\PersistentObject
{
/**
* @ORM\Id
* @ORM\Column(name="mail_fk", type="integer")
* @ORM\ManyToOne(targetEntity="Ajfit\Entity\Mail", inversedBy="replies")
* @ORM\JoinColumn(name="mail_fk", referencedColumnName="pk")
*/
protected $mailFk;
/**
* @ORM\Id
* @ORM\Column(name="ticket_fk", type="integer")
* @ORM\ManyToOne(targetEntity="Ajfit\Entity\Ticket", inversedBy="replies")
* @ORM\JoinColumn(name="ticket_fk", referencedColumnName="pk")
*/
protected $ticketFk;
/**
* @var integer $rating
*
* @ORM\Column(name="rating", type="integer")
*/
protected $rating;
}
由于错误详细说明TicketReply实体没有mailFk关联,但它确实存在问题,我编写查询构建器的原因是什么?
谢谢Andrew
答案 0 :(得分:1)
您的$mailFk
同时包含Column
和ManyToOne
注释。列注释不能用于存储关系。
Doctrine似乎选择在Column
上使用ManyToOne
注释。
删除@ORM\Column
注释:
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Ajfit\Entity\Mail", inversedBy="replies")
* @ORM\JoinColumn(name="mail_fk", referencedColumnName="pk")
*/
protected $mailFk;
对$ticketFk