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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?