From 9ba43e3f259fca5da34d149a17d778f45592b12d Mon Sep 17 00:00:00 2001 From: kj Date: Sat, 5 Sep 2026 16:48:56 -0300 Subject: [PATCH] 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 --- src/Libs/Model.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Libs/Model.php b/src/Libs/Model.php index bfb93dc..24a850d 100644 --- a/src/Libs/Model.php +++ b/src/Libs/Model.php @@ -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(); }