From 3c8f4f695f1b9ec7a188b85e0ce38bc69c697008 Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Sat, 19 Oct 2024 12:38:39 +0200 Subject: Small ORM fixes --- src/application/mystic/forum/Database.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/application/mystic/forum/Database.php') diff --git a/src/application/mystic/forum/Database.php b/src/application/mystic/forum/Database.php index 7a417be..632b2d6 100644 --- a/src/application/mystic/forum/Database.php +++ b/src/application/mystic/forum/Database.php @@ -319,8 +319,11 @@ class Database { $tableName = self::getTableName($entityClassName); $reflClass = new ReflectionClass($entityClassName); $cols = self::getColumns($reflClass); + $values = ArrayUtils::fill(fn($i) => null, count($cols)); + foreach (self::getColumnValues($entity, $cols) as $i => $value) + $values[$i] = $value; $query = "INSERT INTO $tableName VALUES (" . implode(",", ArrayUtils::fill(fn($i) => "$" . ($i + 1), count($cols))) . ");"; - $result = \pg_query_params($this->connection, $query, self::getColumnValues($entity, $cols)); + $result = \pg_query_params($this->connection, $query, $values); if ($result === false) throw new \RuntimeException("Insert failed: " . \pg_last_error($this->connection)); \pg_free_result($result); -- cgit v1.2.3