drrhr20884 2013-12-05 17:01
浏览 44
已采纳

不能在doctrine2中使用JOIN与相关实体

I was guided by this, and I can't understand what's going wrong.

My entities:

/**
 * @ORM\Entity
 * @ORM\Table(name="term")
 */
class Term {
    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    /**
     * @ORM\OneToMany(targetEntity="Description", mappedBy="term")
     **/ 
    private $description;

    //....
}

/**
 * @ORM\Entity
 * @ORM\Table(name="description")
 */
class Description {

    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    /**
     * @Orm\ManyToOne(targetEntity="term", inversedBy="description")
     * @Orm\JoinColumn(name="term_id", referencedColumnName="id")
     **/  
    private $term;
    /**
     * @ORM\Column(type="string", length=8)
     */
    private $normativity;
    //...
}

I need to get terms and filter terms descriptions by one of it fields (normativity in example).

I tried this:

$query = $this->getDoctrine()->getEntityManager()
    ->createQuery("
        SELECT term, desc FROM myTerminologyBundle:Term term
        JOIN term.description desc
        WHERE term.word LIKE :r_word' and desc.normativity IN :norm"         
    )->setParameter('r_word', '%'.$word.'%')->setParameter('norm', array());

and I get the following exceptions:

[Syntax Error] line 0, col 30: Error: Expected IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression, got 'desc'

  • 写回答

3条回答 默认 最新

  • dongxieyi9115 2013-12-05 21:17
    关注

    There are reserved word desc in SQL. I change it to another and it works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器