Skip to content

Commit

Permalink
Use the FIELD function on postgres for order by field value
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtronics committed Jun 17, 2024
1 parent d7a7e22 commit 8a42dfa
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Doctrine/Helpers/FieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 8a42dfa

Please sign in to comment.