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 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。
  • ¥15 抖音看过的视频,缓存在哪个文件