1

我遇到了教义查询生成器的问题,向我抛出 [语义错误] 我正在尝试构建的查询是这样的:-

   $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 关联的错误详细信息,但是它确实存在,我编写查询构建器的原因是否存在问题?

谢谢安德鲁

4

1 回答 1

2

$mailFk有一个Column和一个ManyToOne注释。列注释不能用于存储关系。Doctrine 似乎选择ColumnManyToOne.

删除@ORM\Column注释:

/**
 * @ORM\Id
 * @ORM\ManyToOne(targetEntity="Ajfit\Entity\Mail", inversedBy="replies")
 * @ORM\JoinColumn(name="mail_fk", referencedColumnName="pk")
 */
protected $mailFk;

做同样的事情$ticketFk

于 2012-08-24T19:49:36.270 回答