sync: 2026-09-05

25db49f fix(model): reset query state when database query fails
9cb41d5 fix(model): use RANDOM() for non-MySQL databases in orderBy
This commit is contained in:
kj
2026-09-05 16:48:56 -03:00
parent 54e96ba4bb
commit 9ba43e3f25

View File

@@ -176,6 +176,10 @@ class Model
$vars = json_encode(static::$dbQueryVariables); $vars = json_encode(static::$dbQueryVariables);
if ($resetQuery) {
static::resetQuery();
}
throw new Exception( throw new Exception(
"\nError at query to database.\n" . "\nError at query to database.\n" .
"Query: $query\n" . "Query: $query\n" .
@@ -1008,7 +1012,9 @@ class Model
public static function orderBy(string $value, string $order = 'ASC'): static public static function orderBy(string $value, string $order = 'ASC'): static
{ {
if ($value == "RAND") { 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(); return new static();
} }