sync: 2026-09-05
25db49ffix(model): reset query state when database query fails9cb41d5fix(model): use RANDOM() for non-MySQL databases in orderBy
This commit is contained in:
@@ -176,6 +176,10 @@ class Model
|
||||
|
||||
$vars = json_encode(static::$dbQueryVariables);
|
||||
|
||||
if ($resetQuery) {
|
||||
static::resetQuery();
|
||||
}
|
||||
|
||||
throw new Exception(
|
||||
"\nError at query to database.\n" .
|
||||
"Query: $query\n" .
|
||||
@@ -1008,7 +1012,9 @@ class Model
|
||||
public static function orderBy(string $value, string $order = 'ASC'): static
|
||||
{
|
||||
if ($value == "RAND") {
|
||||
static::$dbQuery['orderBy'] = 'RAND()';
|
||||
$random = static::db()->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql' ? 'RAND()' : 'RANDOM()';
|
||||
static::$dbQuery['orderBy'] = $random;
|
||||
|
||||
return new static();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user