mirror of
https://codeberg.org/vlw/wp.git
synced 2026-02-26 03:51:58 +01:00
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:
parent
d52154192d
commit
1b0a9f385f
2 changed files with 8 additions and 2 deletions
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue