学说查询生成器抛出[语义错误]

时间:2012-08-24 15:35:04

标签: php zend-framework doctrine-orm

我遇到教条查询生成器的问题,给我一个[语义错误]我正在尝试构建的查询是这样的: -

   $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

1 个答案:

答案 0 :(得分:1)

您的$mailFk同时包含ColumnManyToOne注释。列注释不能用于存储关系。 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

执行相同的操作