diff options
author | Jonas Kohl | 2024-10-19 12:38:39 +0200 |
---|---|---|
committer | Jonas Kohl | 2024-10-19 12:38:39 +0200 |
commit | 3c8f4f695f1b9ec7a188b85e0ce38bc69c697008 (patch) | |
tree | 918281d3471e70f85abe6946357a7737186187e5 /src/application/mystic/forum | |
parent | 04b50a77c84e3e92a2ca2fd0e6d239d974429c5b (diff) |
Small ORM fixes
Diffstat (limited to 'src/application/mystic/forum')
-rw-r--r-- | src/application/mystic/forum/Database.php | 5 | ||||
-rw-r--r-- | src/application/mystic/forum/orm/User.php | 3 |
2 files changed, 5 insertions, 3 deletions
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); diff --git a/src/application/mystic/forum/orm/User.php b/src/application/mystic/forum/orm/User.php index 868f385..a1414c3 100644 --- a/src/application/mystic/forum/orm/User.php +++ b/src/application/mystic/forum/orm/User.php @@ -12,8 +12,7 @@ use mystic\forum\attributes\Unique; class User extends Entity { public const SUPERUSER_ID = "SUPERUSER"; - #[PrimaryKey] - public string $id; + #[PrimaryKey] public string $id; #[Unique] public string $name; public string $displayName; #[Unique] public string $email; |