mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
A strange exception thrown when I try to 'order by' a field from a join #6455
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 @ph-freeminds on GitHub (Apr 30, 2020).
Hi everyone,
In a repository, I built a query and added two joins.
query dump :
SELECT vd FROM App\UserService\Entity\KycValidationRequest vd INNER JOIN App\UserService\Entity\UserKycTierLevel utl WITH utl.id = vd.kycTierLevel INNER JOIN App\UserService\Entity\User u WITH u.id = utl.userThis part works, but now I have to sort by a specific field of one of the joins.
updated query dump :
SELECT vd FROM App\UserService\Entity\KycValidationRequest vd INNER JOIN App\UserService\Entity\UserKycTierLevel utl WITH utl.id = vd.kycTierLevel INNER JOIN App\UserService\Entity\User u WITH u.id = utl.user ORDER BY u.birthYear descThis query fails with the following NoSuchPropertyException Exception
Neither the property "birthYear" nor one of the methods "getBirthYear()", "birthYear()", "isBirthYear()", "hasBirthYear()", "__get()" exist and have public access in class "App\UserService\Entity\KycValidationRequestIt seems that Doctrine is trying to search for the 'birthYear' field in the main entity of the query ( KycValidationRequest ) instead of searching in the joined entity ( User ).
I don't understand why ...
According to the documentation ( https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/tutorials/ordered-associations.html ), ordering by nested field should work :
Example : SELECT u, g FROM User u JOIN u.groups g WHERE u.id = 10 ORDER BY g.nameDESCIs it an issue on my side or on yours ?
Thanks :)
@ph-freeminds commented on GitHub (Apr 30, 2020):
I added User entity in the select clause but I still have the same exception
'SELECT vd, u FROM App\UserService\Entity\KycValidationRequest vd INNER JOIN App\UserService\Entity\UserKycTierLevel utl WITH utl.id = vd.kycTierLevel INNER JOIN App\UserService\Entity\User u WITH u.id = utl.user ORDER BY u.birthYear descNeither the property "birthYear" nor one of the methods "getBirthYear()", "birthYear()", "isBirthYear()", "hasBirthYear()", "__get()" exist and have public access in class "App\UserService\Entity\KycValidationRequest@ph-freeminds commented on GitHub (Apr 30, 2020):
Ok sorry guys,
there seems to be a problem with my own paginator..
I close the issue.