DDC-2475: ORDER BY on existing column is added, not replaced #3108

Closed
opened 2026-01-22 14:12:21 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (May 28, 2013).

Jira issue originally created by user jeremylivingston:

It seems that if an entity has an existing ORDER BY clause on a relation that any subsequent ORDER BYs on that field are added instead of replaced.

For example, I have two entities: Person and Membership. Person.Memberships has the following clause specified:

@ORM\OrderBy({"createDate" = "DESC"})

I also have a repository method that uses this relationship and sets the following DQL:

SELECT person, m
FROM \Company\Person person
JOIN person.memberships m
ORDER BY m.createDate ASC

I would expect this query to replace the existing ORDER BY with ORDER BY m.createDate ASC. Instead, it adds the ORDER BY to the existing one, which makes the end result: ORDER BY m.createDate ASC, m.createDate DESC.

This is obviously causing an issue since you can't sort by the same column in different order. Is this behavior by design? If so, is there a way to override the existing ORDER BY setting?

Originally created by @doctrinebot on GitHub (May 28, 2013). Jira issue originally created by user jeremylivingston: It seems that if an entity has an existing ORDER BY clause on a relation that any subsequent ORDER BYs on that field are added instead of replaced. For example, I have two entities: Person and Membership. Person.Memberships has the following clause specified: @ORM\OrderBy({"createDate" = "DESC"}) I also have a repository method that uses this relationship and sets the following DQL: SELECT person, m FROM \Company\Person person JOIN person.memberships m ORDER BY m.createDate ASC I would expect this query to replace the existing ORDER BY with ORDER BY m.createDate ASC. Instead, it adds the ORDER BY to the existing one, which makes the end result: ORDER BY m.createDate ASC, m.createDate DESC. This is obviously causing an issue since you can't sort by the same column in different order. Is this behavior by design? If so, is there a way to override the existing ORDER BY setting?
admin added the Bug label 2026-01-22 14:12:21 +01:00
admin closed this issue 2026-01-22 14:12:21 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 5, 2013):

Comment created by @FabioBatSilva:

Fixed : 753d63c2d4

@doctrinebot commented on GitHub (Jun 5, 2013): Comment created by @FabioBatSilva: Fixed : https://github.com/doctrine/doctrine2/commit/753d63c2d48facdecba5d84f6ed2450024de2867
Author
Owner

@doctrinebot commented on GitHub (Jun 5, 2013):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Jun 5, 2013): 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#3108