0

I've see the major post on the Doctrine "LIKE" query topic (see, for instance this one). I have a SYmfony2 application. In a controller I call an entity repository to make a query. In particular, in the entity repository I define the following function:

return $this->getEntityManager()
        ->createQuery("SELECT p FROM AcmePromoBundle:Promo p 
            JOIN p.product pr 
            WHERE pr.name LIKE 'La'")->getResult(); 

It works but doesn't return anything, because there is no Product (pr) such that its name is La. Then, I try to add the % character inside the SQL query like follows here:

"SELECT p FROM AcmePromoBundle:Promo p JOIN p.product pr WHERE pr.name LIKE 'La%'" 

and here:

"SELECT p FROM AcmePromoBundle:Promo p JOIN p.product pr WHERE pr.name LIKE La%" 

but the following error is returned "Class true does not exist". I also tried to use "setParameter" function but it doesn't work! Any idea?

Community
  • 1
  • 1
JeanValjean
  • 17,172
  • 23
  • 113
  • 157
  • Although I'm using a bit oldish release of 2.0 Doctrine, queries like that one worked with no problem. Maybe you should update your Doctrine to latest release? – Jovan Perovic Jun 02 '12 at 09:21
  • Mhhh! I'm using the last Symfony2 release! I suppose that Doctrine is already updated! – JeanValjean Jun 02 '12 at 09:23
  • True but you should check nevertheless. There might be a bug that was fixed in some of later releases ;) – Jovan Perovic Jun 02 '12 at 09:26
  • 1
    Are you absolutely certain this query is the cause? I don't see anything anywhere which would show up in a string as 'true'. Have you checked your mappings are correct as well (iirc you can use validate-mappings in command line tool)? I've used join queries in many D2 versions and they always worked fine, I don't think LIKE should have an effect on it. – Jani Hartikainen Jun 02 '12 at 09:26
  • @JaniHartikainen No I'm not! In fact I posted the error that happens when I call this function. You drawn a possible cause... I'm going to investigate. I'll keep you posted! – JeanValjean Jun 02 '12 at 09:32
  • @JaniHartikainen Well! I don't know what is happening. I check the entity classes, they seems to be ok! The error happens in `...\Acme\vendor\doctrine\lib\Doctrine\ORM\Proxy\ProxyFactory.php` at **line 194**. The code is `if (($paramClass = $param->getClass()) !== null)`. So it seems that the `getClass()` function of the `$param` variable return true! – JeanValjean Jun 02 '12 at 14:58

1 Answers1

0

Now It works! I only added the __toString function inside all the entity classes! E.g.:

public function __toString(){
    return '\Acme\PromoBundle\Entity\Promo';
}  
JeanValjean
  • 17,172
  • 23
  • 113
  • 157