JeanValjean
JeanValjean

Reputation: 17713

Doctrine2 "Like" SQL query and "Class true does not exist" error

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?

Upvotes: 0

Views: 493

Answers (1)

JeanValjean
JeanValjean

Reputation: 17713

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

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

Upvotes: 0

Related Questions