mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
EntityRepository.count don't handle Criteria array/object #5870
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 @Stoakes on GitHub (Feb 4, 2018).
Originally assigned to: @Ocramius on GitHub.
Hi
I'm trying to count several entities using
EntityRepository.count()method. My criteria is quite complex so I use theCriteriaclass to express it. However it is not working. My tests let me think that there is an issue between the signature ofEntityRepository.countandEntityPersister.count.Use Case
I have an
Officeobject. An office has auser(Many to One withUserentity) and stands at a floor (integer).I want to count all the
Officebelonging to a user and higher than a given floor.Attempts
Based on the documentation I tried
It gives me Unrecognized field: 0 full stack trace
Of course if I try without the array:
I get a
Type error: Argument 1 passed to Doctrine\ORM\EntityRepository::count() must be of the type array, object given, called in /app/src/Service/OfficeService.php on line 189.Workaround
My current workaround (and what makes me think it is a bug), is:
In my own
OfficeRepository, add acountBismethod which uses theEntityRepository.countimplementation:Doctrine info
Thanks
@Ocramius commented on GitHub (Feb 5, 2018):
Is this bit in your example intentional?
@Ocramius commented on GitHub (Feb 5, 2018):
Ah, I see what is wrong there. This is a naming mismatch in the API.
You probably want to use the
Doctrine\Common\Collections\Selectableinterface.Usage is as follows:
The name
criteria(for parameters) is a restrictive criteria ofkey => valuescalar values to restrict the search upon, and that's something we had since even beforeDoctrine\Common\Collections\Selectablewas introduced.@holtkamp commented on GitHub (Feb 5, 2018):
The following links might be useful when encountering the limitations of
Doctrine\Common\Collections\Selectable:@Stoakes commented on GitHub (Feb 5, 2018):
Hi.
Thank you for your time. However, I think we misunderstood.
Let me try to reformulate.
Currently in
Doctrine\ORM\EntityRepository, we have that piece of code (which accepts only array)The underlying implementation, described in
Doctrine\ORM\Persisters\Entity\EntityPersisteraccepts aCriteria.The bug is that the array type constraint in
EntityRepository.countjust prevent me from using aCriteria. However, if I manually remove this constraint in the dependency code, passing aCriteriaworks fine.My solution would be to just remove the type constraint, and everything would work fine.
Is my explanation now clearer ?
@Ocramius commented on GitHub (Feb 5, 2018):
Yes, that's clearer, but it won't be done. Please use the Selectable API
instead.
On 5 Feb 2018 20:09, "Antoine Beyet" notifications@github.com wrote:
@dorian53 commented on GitHub (Apr 29, 2020):
Hello,
The comment Criteria is very ambigous ! I had the same problem...