DDC-23: Limit and offset in QueryBuilder #27

Closed
opened 2026-01-22 12:24:47 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 29, 2009).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user itoijala:

Currently (2.0 Alpha 1) QueryBuilder does not support limit or offset functionality. These were supported in Doctrine 1 and should be added. QueryBuilder's value is significantly lower without these features because simple pagination is not possible. Methods limit($limit) and offset($offset) should be added to QueryBuilder, like in Doctrine 1. Query already has support for limit and offset, so this should not be a large change.

Originally created by @doctrinebot on GitHub (Sep 29, 2009). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user itoijala: Currently (2.0 Alpha 1) QueryBuilder does not support limit or offset functionality. These were supported in Doctrine 1 and should be added. QueryBuilder's value is significantly lower without these features because simple pagination is not possible. Methods limit($limit) and offset($offset) should be added to QueryBuilder, like in Doctrine 1. Query already has support for limit and offset, so this should not be a large change.
admin added the Improvement label 2026-01-22 12:24:48 +01:00
admin closed this issue 2026-01-22 12:24:48 +01:00
Author
Owner

@doctrinebot commented on GitHub (Sep 29, 2009):

Comment created by romanb:

You can set the limit/offset on the query when you're done building it.

$qb = $em->createQueryBuilder();
//.. build your query
$q = $qb->getQuery();
$q->setFirstResult($offset);
$q->setMaxResults($limit);
$result = $q->getResult();

LIMIT/OFFSET is no longer part of DQL.

We may consider adding forwarding methods to QueryBuilder, similar to setParameter() but only if there is some advantage to it. Is there?

@doctrinebot commented on GitHub (Sep 29, 2009): Comment created by romanb: You can set the limit/offset on the query when you're done building it. ``` $qb = $em->createQueryBuilder(); //.. build your query $q = $qb->getQuery(); $q->setFirstResult($offset); $q->setMaxResults($limit); $result = $q->getResult(); ``` LIMIT/OFFSET is no longer part of DQL. We may consider adding forwarding methods to QueryBuilder, similar to setParameter() but only if there is some advantage to it. Is there?
Author
Owner

@doctrinebot commented on GitHub (Oct 1, 2009):

Comment created by @guilhermeblanco:

Although it's currently possible to be done via Query retrieval, I think Ismo is correct and we should add 2 delegate methods to setFirstResult and setMaxResults.
That would make QueryBuilder more complete and easy to follow the workflow (Query <=> QueryBuilder).

I'm +1 to add it. If you agree, I can implement the patch and attach to next release.

@doctrinebot commented on GitHub (Oct 1, 2009): Comment created by @guilhermeblanco: Although it's currently possible to be done via Query retrieval, I think Ismo is correct and we should add 2 delegate methods to setFirstResult and setMaxResults. That would make QueryBuilder more complete and easy to follow the workflow (Query <=> QueryBuilder). I'm +1 to add it. If you agree, I can implement the patch and attach to next release.
Author
Owner

@doctrinebot commented on GitHub (Oct 1, 2009):

Comment created by @guilhermeblanco:

I found this enhancement interesting and implemented this. I committed a patch to support it in trunk, so in next alpha it'll be available.

Changeset: http://trac.doctrine-project.org/changeset/6415

Cheers,

@doctrinebot commented on GitHub (Oct 1, 2009): Comment created by @guilhermeblanco: I found this enhancement interesting and implemented this. I committed a patch to support it in trunk, so in next alpha it'll be available. Changeset: http://trac.doctrine-project.org/changeset/6415 Cheers,
Author
Owner

@doctrinebot commented on GitHub (Oct 1, 2009):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Oct 1, 2009): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#27