0
我會在查詢中使用一個字段,但我收到此錯誤: [語義錯誤] line 0,col 78 near'resource_id =':Error:Class Dt \ TagBundle \ Entity \ Tagging has沒有字段或協會命名RESOURCE_IDSymfony2原則查詢實體錯誤
這是我的實體標記:
<?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;
}
在我的數據庫表是:標記(ID,TAG_ID,RESOURCE_TYPE,RESOURCE_ID) 其中TAG_ID對應的ID的表格:標籤(id,name) 和RESOURCE_ID對應的用戶表用戶(ID,姓名,...)
這是我的搜索查詢:
$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();
我該怎麼辦定義RESOURCE_ID ???謝謝
謝謝,現在工作!爲什麼resourceId而不是resource_id?你能解釋一下嗎? @Carlos Granados –
我在答案中解釋了它:在教義查詢中你需要使用字段的名稱,而不是保存它們的數據庫列的名稱 –