mirror of
https://github.com/doctrine/orm.git
synced 2026-04-29 01:13:14 +02:00
DDC-3661: Doctrine\ORM\LazyCriteriaCollection unpredictable count() #4495
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Apr 4, 2015).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user fedikw:
When criteria has set $maxResults Doctrine\ORM\LazyCriteriaCollection::count() can return different result depend when it was called, before initialize() or after.
When LazyCriteriaCollection not initialized then count() return Total from database,
when LazyCriteriaCollection have been initialized then count() return Total from "collection" that is limited by Criteria::$maxResults.
Example you have 30 items in database and Criteria::$maxResults = 5, then:
It is very confuse ;)
also I not sure which behaviour is right: it should always return Total from database or Total depend from Criteria::$maxResults
@doctrinebot commented on GitHub (Apr 4, 2015):
@doctrinebot commented on GitHub (Apr 4, 2015):
Comment created by @ocramius:
This is indeed a bug: consider writing an example test case so that we can work on it.
@doctrinebot commented on GitHub (Apr 4, 2015):
Comment created by fedikw:
I think I found solution, I try make pull request tomorrow
@doctrinebot commented on GitHub (Apr 5, 2015):
Comment created by fedikw:
there it is https://github.com/doctrine/doctrine2/pull/1372
-For exaple can take that docs.doctrine-project.org/en/latest/reference/working-with-associations.html#filtering-collections-
For example for User entity:
if you have BirthdayUsers in database 100 and run next code:
@doctrinebot commented on GitHub (Apr 6, 2015):
Comment created by @doctrinebot:
A related Github Pull-Request [GH-1372] was labeled:
https://github.com/doctrine/doctrine2/pull/1372
@fracz commented on GitHub (Apr 9, 2018):
This bug just bit me, too.
IMO, this query should take LIMIT & OFFSET into consideration, if set.
@koteq commented on GitHub (Nov 22, 2018):
Five years ago in a galaxy far, far away someone invented a LazyCriteriaCollection #882.
I wish the behavior to be documented somehow, at least here. It could have saved some hours debugging.