0

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 Answer 1

0

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")
2
  • Thanks, now work!!!! Why resourceId and not resource_id?? Can you explain, please? @Carlos Granados
    – Luca M
    Nov 4, 2015 at 10:01
  • I explained it in the answer: in doctrine queries you need to use the name of the fields, not the name of the database columns where they are saved Nov 4, 2015 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.