Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mfsianoopj opened this issue Sep 2, 2014 · 3 comments

Comments

@mfsianoopj
Copy link

I have following update query written using doctrine query builder:

$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.

@Ocramius
Copy link
Member

Ocramius commented Sep 2, 2014

DQL doesn't allow limit on UPDATE queries, as it is not portable.
On Sep 2, 2014 6:25 AM, "mfsianoopj" notifications@github.com wrote:

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.


Reply to this email directly or view it on GitHub
#326.

@stof
Copy link
Member

stof commented Sep 2, 2014

and this has nothing to do with DoctrineBundle. This issue tracker is not the issue tracker of the ORM

@stof stof closed this as completed Sep 2, 2014
@deeky666
Copy link
Member

deeky666 commented Sep 2, 2014

Not sure if that works but you could try to solve this by using an EXISTS expression condition with a subquery that selects the limited resultset and then performing the UPDATE operation on that resultset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants