From a261ce9e016df558743331c98056e13d0f1f3a16 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Mon, 16 Feb 2026 13:36:26 +0100 Subject: [PATCH] fix: use AUTO_INCREMENT of table as id of new posts --- src/Posts/Post.php | 5 ++++- src/Posts/PostMeta.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Posts/Post.php b/src/Posts/Post.php index 34d5282..48df4c2 100644 --- a/src/Posts/Post.php +++ b/src/Posts/Post.php @@ -47,6 +47,9 @@ return self::from_name($title); } + // Current auto increment value will be the id for this entity + $id = Database::current()->latest(Posts::TABLE_NAME); + $values = [ Posts::ID->value => null, Posts::POST_AUTHOR->value => 0, @@ -77,7 +80,7 @@ throw new Exception("Failed to create database entity"); } - return self::from_name($title); + return new static($id); } public function __construct(public readonly int $id) { diff --git a/src/Posts/PostMeta.php b/src/Posts/PostMeta.php index e5c54d9..0d51216 100644 --- a/src/Posts/PostMeta.php +++ b/src/Posts/PostMeta.php @@ -64,6 +64,9 @@ return $model; } + // Current auto increment value will be the id for this entity + $id = Database::current()->latest(PostMetaTable::TABLE_NAME); + $values = [ PostMetaTable::META_ID->value => null, PostMetaTable::POST_ID->value => $post->id, @@ -75,7 +78,7 @@ 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) {