fix: use AUTO_INCREMENT of table as id of new posts (#9)

Reviewed-on: https://codeberg.org/vlw/wp/pulls/9
This commit is contained in:
Victor Westerlund 2026-02-16 13:37:52 +01:00
parent d52154192d
commit b92cb8d960
2 changed files with 8 additions and 2 deletions

View file

@ -47,6 +47,9 @@
return self::from_name($title); return self::from_name($title);
} }
// Current auto increment value will be the id for this entity
$id = Database::current()->latest(Posts::TABLE_NAME);
$values = [ $values = [
Posts::ID->value => null, Posts::ID->value => null,
Posts::POST_AUTHOR->value => 0, Posts::POST_AUTHOR->value => 0,
@ -77,7 +80,7 @@
throw new Exception("Failed to create database entity"); throw new Exception("Failed to create database entity");
} }
return self::from_name($title); return new static($id);
} }
public function __construct(public readonly int $id) { public function __construct(public readonly int $id) {

View file

@ -64,6 +64,9 @@
return $model; return $model;
} }
// Current auto increment value will be the id for this entity
$id = Database::current()->latest(PostMetaTable::TABLE_NAME);
$values = [ $values = [
PostMetaTable::META_ID->value => null, PostMetaTable::META_ID->value => null,
PostMetaTable::POST_ID->value => $post->id, PostMetaTable::POST_ID->value => $post->id,
@ -75,7 +78,7 @@
throw new Exception("Failed to create database entity"); throw new Exception("Failed to create database entity");
} }
return new static(self::get_post_meta($post, $meta_key)->id); return new static($id);
} }
public function __construct(public readonly int $id) { public function __construct(public readonly int $id) {