DDC-1116: Sort by association id #1396

Closed
opened 2026-01-22 13:13:01 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 15, 2011).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user rande:

For now it is not possible to sort a result by an association field.

ie : SELECT * FROM Post as p ORDER BY p.Author

Originally created by @doctrinebot on GitHub (Apr 15, 2011). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user rande: For now it is not possible to sort a result by an association field. ie : SELECT \* FROM Post as p ORDER BY p.Author
admin added the Improvement label 2026-01-22 13:13:01 +01:00
admin closed this issue 2026-01-22 13:13:02 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 3, 2011):

Comment created by justhannes:

I agree, maybe even make it sortable by a field of the target?

ie: SELECT * FROM Post as p ORDER BY p.Author.Name

@doctrinebot commented on GitHub (Jun 3, 2011): Comment created by justhannes: I agree, maybe even make it sortable by a field of the target? ie: SELECT \* FROM Post as p ORDER BY p.Author.Name
Author
Owner

@doctrinebot commented on GitHub (Jul 8, 2011):

Comment created by guillaumec@gmail.com:

I agree with Johannes about sorting by a field of the target.

Without this feature or a decent workaround, I will have to stop using doctrine for my project.

@doctrinebot commented on GitHub (Jul 8, 2011): Comment created by guillaumec@gmail.com: I agree with Johannes about sorting by a field of the target. Without this feature or a decent workaround, I will have to stop using doctrine for my project.
Author
Owner

@doctrinebot commented on GitHub (Jul 8, 2011):

Comment created by @guilhermeblanco:

Hi,

I think the first one if doable.
But please take in mind that it's doable if your association is the owning side and is a *ToOne side. I say that because it could generate a SQL like this:

SELECT ... FROM posts p ORDER BY p.author_id

If it's a *ToMany, it's impossible. No way to achieve it.
But if it's the inverse side, it is doable, but it would require a JOIN. We dropped this "auto inclusion" of JOINs back in RC3 because it is not stable and to make it stable would make the overall Parser performance much slow. The other reason is that developer is pretty able to do the join yourself. I'll take the first comment as an example:

SELECT ... FROM Post p INNER JOIN p.Author a ORDER BY a.name

This one is already supported. =)

Cheers,

@doctrinebot commented on GitHub (Jul 8, 2011): Comment created by @guilhermeblanco: Hi, I think the first one if doable. But please take in mind that it's doable if your association is the owning side and is a *ToOne side. I say that because it could generate a SQL like this: ``` SELECT ... FROM posts p ORDER BY p.author_id ``` If it's a *ToMany, it's impossible. No way to achieve it. But if it's the inverse side, it is doable, but it would require a JOIN. We dropped this "auto inclusion" of JOINs back in RC3 because it is not stable and to make it stable would make the overall Parser performance much slow. The other reason is that developer is pretty able to do the join yourself. I'll take the first comment as an example: ``` SELECT ... FROM Post p INNER JOIN p.Author a ORDER BY a.name ``` This one is already supported. =) Cheers,
Author
Owner

@doctrinebot commented on GitHub (Jul 8, 2011):

Comment created by guillaumec@gmail.com:

Thank you Guilherme Blanco, this fixes the issue for me!

@doctrinebot commented on GitHub (Jul 8, 2011): Comment created by guillaumec@gmail.com: Thank you Guilherme Blanco, this fixes the issue for me!
Author
Owner

@doctrinebot commented on GitHub (Aug 14, 2011):

Comment created by @guilhermeblanco:

Added support to SingleValuedPathExpression in ORDER BY since this commit: a0ca506db7

Thanks for the report.

Cheers,

@doctrinebot commented on GitHub (Aug 14, 2011): Comment created by @guilhermeblanco: Added support to SingleValuedPathExpression in ORDER BY since this commit: https://github.com/doctrine/doctrine2/commit/a0ca506db7e577c55dd89544bfd8ba08962c3cfe Thanks for the report. Cheers,
Author
Owner

@doctrinebot commented on GitHub (Aug 14, 2011):

Issue was closed with resolution "Fixed"

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

No dependencies set.

Reference: doctrine/archived-orm#1396