Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine and LIKE query

I have entity for Doctrine:

<?php /**  * @Entity  * @Table(name="orders")  */ class Orders {     /** @Id @Column(name="OID",type="integer") @GeneratedValue */     private $id;     /** @Column(name="Product",type="string")*/         private $product;     /** @Column(name="RegCode",type="string")*/         private $reg_code;     /** @Column(name="OrderEmail",type="string")*/     private $email; } 

I need make query like this:

select * from `orders` where `OrderEmail`='[email protected]' and `Product` LIKE 'My Products%' 

I try handle query without like:

$em->getRepository("Orders")->findByEmailAndProduct($uname,$product); 

But it make error. Why? Can I do this query without DQL? I want make this query use magic methods findBy**

like image 508
Eugene Avatar asked Nov 17 '11 09:11

Eugene


1 Answers

This is not possible with the magic find methods. Try using the query builder:

$result = $em->getRepository("Orders")->createQueryBuilder('o')    ->where('o.OrderEmail = :email')    ->andWhere('o.Product LIKE :product')    ->setParameter('email', '[email protected]')    ->setParameter('product', 'My Products%')    ->getQuery()    ->getResult(); 
like image 160
Kristian Zondervan Avatar answered Sep 29 '22 10:09

Kristian Zondervan