7

I have the following code

$qb = $this->createQueryBuilder('cs')
        ->update()
        ->set('cs.is_active', 1)
        ->where('cs.reward_coupon = :reward_coupon')
        ->setMaxResults($limit)
        ->setParameter('reward_coupon', $rewardCoupon);
$qb->getQuery()->execute(); 

This doesn’t apply the LIMIT in the resultant query.

Ramesh
  • 4,223
  • 2
  • 16
  • 24
acj89
  • 258
  • 2
  • 6

2 Answers2

3

setMaxResult() has to be your last Doctrine statement in order to properly works

example :

    $qb = $this->createQueryBuilder('cs')
    ->update()
    ->set('cs.is_active', 1)
    ->where('cs.reward_coupon = :reward_coupon')
    ->setParameter('reward_coupon', $rewardCoupon)
    ->setMaxResults($limit);


     return $qb->getQuery()->execute(); 
Charles-Antoine Fournel
  • 1,713
  • 1
  • 25
  • 37
-1

I think that this may help

$limit=50;
$i=0;
$qb = $this->createQueryBuilder('cs')
->update()
->set('cs.is_active', 1)
->where('cs.reward_coupon = :reward_coupon')
->setParameter('reward_coupon', $rewardCoupon)
->setFirstResult($i)
->setMaxResults($limit);
$qb->getQuery()->execute(); 
Sunil Chhimpa
  • 404
  • 1
  • 4
  • 12