0
votes

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?

1
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
Mhhh! I'm using the last Symfony2 release! I suppose that Doctrine is already updated!JeanValjean
True but you should check nevertheless. There might be a bug that was fixed in some of later releases ;)Jovan Perovic
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
@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

1 Answers

0
votes

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

public function __toString(){
    return '\Acme\PromoBundle\Entity\Promo';
}