1
$data = $this
        ->entityManager
        ->getRepository('io\V1\Rest\Advertisers\AdvertisersEntity')
        ->findBy(
            array('camapId' => '1465' , 'campName'=>'mytest')                
        );

here wanted to add the condition camapId='1465' OR campName like '%mytest%'
rather than camapId='1465' AND campName ='mytest'
so is there any way to achieve this?.

Wilt
  • 41,477
  • 12
  • 152
  • 203
htngapi
  • 365
  • 3
  • 7

2 Answers2

3

You can make the search conditions in your repositories as complicated as you want if you use Doctrine2 DQL or the Doctrine2 QueryBuilder. You can read about this here (DQL) and here (QueryBuilder) in the Doctrine documentation.

There are a lot of examples online about how to use DQL and QueryBuilder to reach your result.

I think it will be something like:

$data = $this->createQueryBuilder('a')
             ->where('a.camapId = 1465')
             ->orWhere('a.campName = mytest')
             ->getQuery()
             ->getResult();
Wilt
  • 41,477
  • 12
  • 152
  • 203
1
    $campIdsToFilter = $campIdsToFilterArray =array();
    $query = $this->entityManager->createQuery("SELECT DISTINCT a.campId FROM io\V1\Rest\Advertisers\AdvertisersEntity a where a.campName like'%mytest%' OR a.campId=1465");

    $campIdsToFilter = $query->getResult();
    foreach($campIdsToFilter as $ke=> $value){
    $campIdsToFilterArray[] =$value;

    }


    $data = $this
            ->entityManager
            ->getRepository('io\V1\Rest\Advertisers\AdvertisersEntity')
            ->findBy(
                array('campId' => $campIdsToFilterArray) , 
                $pageSize,  // limit
                $pageSize * ($page - 1) // offset              
            );
htngapi
  • 365
  • 3
  • 7