dongxie8856 2015-11-04 09:38
浏览 44
已采纳

Symfony2 Doctrine查询实体错误

I would use a field in a query but i receive this error: [Semantical Error] line 0, col 78 near 'resource_id =': Error: Class Dt\TagBundle\Entity\Tagging has no field or association named resource_id

This is my entity Tagging:

<?php

 namespace Dt\TagBundle\Entity;
 use Doctrine\ORM\Mapping as ORM;
 use Doctrine\ORM\Mapping\UniqueConstraint;
 use FPN\TagBundle\Entity\Tagging as BaseTagging;


 /**
  * Dt\TagBundle\Entity\Tagging
  *
  * @ORM\Table(uniqueConstraints={@UniqueConstraint(name="tagging_idx",      columns={"tag_id", "resource_type", "resource_id"})})
  * @ORM\Entity
  */
 class Tagging extends BaseTagging
 {
/**
 * @var integer $id
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\ManyToOne(targetEntity="Dt\TagBundle\Entity\Tag")
 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
 **/
protected $tag;
 }

The table on my db is: Tagging(id, tag_id, resource_type, resource_id) where tag_id correspond at the id of the table: Tag(id,name) and resource_id correspond at the User table User(id, name , surname, ...)

This is my search query:

$query = $em->createQueryBuilder()
         ->select('uu')   
         ->from('DtEcBundle:User', 'uu')
         ->innerJoin("DtTagBundle:Tag","tg", "WITH", "tg.id = tig.tag")
         ->innerJoin("DtTagBundle:Tagging","tig", "WITH", "tig.resource_id = uu.id")
         ->innerJoin("DtTagBundle:Tag","tg", "WITH", "tg.id = tig.tag") 
         ->where("uu.surname LIKE :search OR uu.name LIKE :search OR uu.profession LIKE :search OR tg.name LIKE :search")
         ->setParameter("search",$search.'%')
            ->getQuery();

How can i do to define resource_id??? Thanks

  • 写回答

1条回答 默认 最新

  • drkwpgrdb092239314 2015-11-04 09:51
    关注

    If you look at the source code for the base class for your entity, you will find that the field is called resourceId not resource_id. It is saved in the resource_id column in the database but that is not what you need to use in Doctrine queries. So, you should change it to:

         ->innerJoin("DtTagBundle:Tagging","tig", "WITH", "tig.resourceId = uu.id")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测