Update query with LIMIT (setMaxResults) in doctrine2 with createQueryBuilder not working

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 does not apply LIMIT in the resulting query.

+5
source share
2 answers

setMaxResult () must be your last Doctrine statement to work correctly

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(); 
+1
source

I think 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(); 
-1
source

Source: https://habr.com/ru/post/1201563/


All Articles