fix(model): use RANDOM() for non-MySQL databases in orderBy

This commit is contained in:
kj
2026-09-05 16:37:37 -03:00
parent d0c4b3c503
commit 9cb41d51d0

View File

@@ -1008,7 +1008,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();
}