Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update query with LIMIT ( setMaxResults ) in doctrine2 using 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 doesn’t apply the LIMIT in the resultant query.

like image 263
acj89 Avatar asked Sep 01 '14 12:09

acj89


1 Answers

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(); 
like image 164
Charles-Antoine Fournel Avatar answered Nov 11 '22 21:11

Charles-Antoine Fournel