From 8a42dfa154ff9f20652a71465b1c9899f7c09b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Mon, 17 Jun 2024 21:20:23 +0200 Subject: [PATCH] Use the FIELD function on postgres for order by field value --- src/Doctrine/Helpers/FieldHelper.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Doctrine/Helpers/FieldHelper.php b/src/Doctrine/Helpers/FieldHelper.php index d1c9eee6..d8654af6 100644 --- a/src/Doctrine/Helpers/FieldHelper.php +++ b/src/Doctrine/Helpers/FieldHelper.php @@ -87,13 +87,11 @@ public static function addOrderByFieldValues(QueryBuilder $qb, string $field_exp $key = 'field2_' . md5($field_expr); - //If we are on MySQL, we can just use the FIELD function - if ($db_platform instanceof AbstractMySQLPlatform) { + //If we are on MySQL, we can just use the FIELD function, for postgres we can use our custom defined one + if ($db_platform instanceof AbstractMySQLPlatform || $db_platform instanceof PostgreSQLPlatform) { $qb->orderBy("FIELD($field_expr, :field_arr)", $order); } else { - //Generate a unique key from the field_expr - - //Otherwise we have to it using the FIELD2 function + //Otherwise use the portable version using string concatenation self::addSqliteOrderBy($qb, $field_expr, $key, $values, $order); }