A strange exception thrown when I try to 'order by' a field from a join #6455

Closed
opened 2026-01-22 15:33:33 +01:00 by admin · 2 comments
Owner

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.user

This 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 desc

This 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\KycValidationRequest

It 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.name DESC

Is it an issue on my side or on yours ?
Thanks :)

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.user` This 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 desc` This 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\KycValidationRequest` It 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.name `DESC Is it an issue on my side or on yours ? Thanks :)
admin closed this issue 2026-01-22 15:33:33 +01:00
Author
Owner

@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 desc

Neither 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): 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 desc` `Neither the property "birthYear" nor one of the methods "getBirthYear()", "birthYear()", "isBirthYear()", "hasBirthYear()", "__get()" exist and have public access in class "App\UserService\Entity\KycValidationRequest`
Author
Owner

@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.

@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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6455