fix(model): use RANDOM() for non-MySQL databases in orderBy
This commit is contained in:
@@ -1008,7 +1008,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user