DDC-3193: Paginator hydrating the iterator with only half the limit #3959

Closed
opened 2026-01-22 14:32:23 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 26, 2014).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user alanhartless:

When using paginator on a left join for a one to many association, Doctrine is only hydrating half the requested results via the limit set by setMaxResults(). It is giving the correct total as indicated by count() but getIterator() is only returning half the requested results.

For example, I have 82 results, with a setMaxResults(50), getIterator() only has 25 hydrated!

My entities are:

Submission
/****
* @ORM\OneToMany(targetEntity="Result", mappedBy="submission", cascade={"persist", "remove", "refresh", "detach"})
*/
private $results;

Result

/****
 * @ORM\ManyToOne(targetEntity="Submission", inversedBy="results")
 * @ORM\JoinColumn(name="submission_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
 ****/
private $submission;

And I'm using the following query builder in the submission repository:
$q = $this->createQueryBuilder('s')
->select('s, r')
->leftJoin('s.results', 'r')
->setFirstResult(0)
->setMaxResults(0);

It seems to be counting each submissions result as one rather than each submission. So it is returning 50, although its 50 results within 25 submissions. I need to find a way to get it to return 50 submissions instead. Maybe I'm doing something wrong?

Originally created by @doctrinebot on GitHub (Jun 26, 2014). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user alanhartless: When using paginator on a left join for a one to many association, Doctrine is only hydrating half the requested results via the limit set by setMaxResults(). It is giving the correct total as indicated by count() but getIterator() is only returning half the requested results. For example, I have 82 results, with a setMaxResults(50), getIterator() only has 25 hydrated! My entities are: Submission /**** \* @ORM\OneToMany(targetEntity="Result", mappedBy="submission", cascade={"persist", "remove", "refresh", "detach"}) */ private $results; Result ``` /**** * @ORM\ManyToOne(targetEntity="Submission", inversedBy="results") * @ORM\JoinColumn(name="submission_id", referencedColumnName="id", nullable=false, onDelete="CASCADE") ****/ private $submission; ``` And I'm using the following query builder in the submission repository: $q = $this->createQueryBuilder('s') ->select('s, r') ->leftJoin('s.results', 'r') ->setFirstResult(0) ->setMaxResults(0); It seems to be counting each submissions result as one rather than each submission. So it is returning 50, although its 50 results within 25 submissions. I need to find a way to get it to return 50 submissions instead. Maybe I'm doing something wrong?
admin added the Bug label 2026-01-22 14:32:23 +01:00
admin closed this issue 2026-01-22 14:32:24 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 26, 2014):

Comment created by stof:

Can you post your code configuring the paginator too ?

@doctrinebot commented on GitHub (Jun 26, 2014): Comment created by stof: Can you post your code configuring the paginator too ?
Author
Owner

@doctrinebot commented on GitHub (Jun 26, 2014):

Comment created by alanhartless:

Looks like this was my bad. After getting frustrated with trying to get it to work, I had tried all kinds of things including $results = new Paginator($query, false); while I was debugging to see if $fetchJoinCollection made a difference. I had rearranged my query multiple times but forgot to remove the false so of course it continued to fail. Now that I've removed it (so it defaults to true), the query works correctly.

Thanks,
Alan

@doctrinebot commented on GitHub (Jun 26, 2014): Comment created by alanhartless: Looks like this was my bad. After getting frustrated with trying to get it to work, I had tried all kinds of things including $results = new Paginator($query, false); while I was debugging to see if $fetchJoinCollection made a difference. I had rearranged my query multiple times but forgot to remove the false so of course it continued to fail. Now that I've removed it (so it defaults to true), the query works correctly. Thanks, Alan
Author
Owner

@doctrinebot commented on GitHub (Jun 26, 2014):

Issue was closed with resolution "Invalid"

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

No dependencies set.

Reference: doctrine/archived-orm#3959