acj89
acj89

Reputation: 258

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.

Upvotes: 7

Views: 7193

Answers (2)

Sunil Chhimpa
Sunil Chhimpa

Reputation: 404

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(); 

Upvotes: -1

Charles-Antoine Fournel
Charles-Antoine Fournel

Reputation: 1783

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(); 

Upvotes: 4

Related Questions