mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
QueryBuilder->{orderBy/addOrderBy} do not support instances of Order enum type #7537
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 @wayne530 on GitHub (Jul 24, 2025).
Feature Request
Recently, a new deprecation warning started showing for the old
Criteria::ASCandCriteria::DESCconstants, suggesting thatOrder::AscendingandOrder::Descendingshould be used, respectively. This does work fine when usingCriteria::create()->orderBy, but it does not work forQueryBuilder->orderByorQueryBuilder->addOrderBy, which generates the following exception:In order to get around this, we must explicitly use
Order::Ascending->valueorOrder::Descending->value, which is quite a bit more verbose. Seems like it could potentially make sense to add this support into QueryBuilder and it seems relatively straightforward as well.What
Support for:
instead of:
Why
It's more concise and other interfaces that provide ordering for queries support it (
Criteria::create()->orderBy).How
The simplest way would be to modify
addOrderByandorderByof theQueryBuilderclass and allow them to accept instances ofOrder. UpdateExpr\OrderBy's constructor to also accept instances orOrderand convert them to their corresponding string value internally.